如何导入lib文件?扫描仪发生FileNotFoundException

时间:2019-06-05 13:30:34

标签: android

我收到以下错误:

logcat output with the error

scan = new Scanner(new File("file:///android_lib/"+StationNM+".csv"));

我在lib文件夹中有아현.csv,但是android抛出FileNotFoundException

我该如何解决?

我的来源是

mport java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Scanner;
import java.lang.Object;

public class model {


    public float modelPredict(String StationNM, String UPandDOWN, int day, int hour, int minute)
    {
 Scanner scan = null;
        try {
            scan = new Scanner(new File("file:///android_lib/"+StationNM+".csv"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        ArrayList<String[]> records = new ArrayList<String[]>();
        ArrayList<Integer> model_list = new ArrayList<Integer>();

        while (scan.hasNext()) {
            String[] record;
            record = scan.nextLine().split(",");
            records.add(record);
        }
}

this issue was solved

1 个答案:

答案 0 :(得分:1)

scan = new Scanner(new File("file:///android_lib/"+StationNM+".csv"));

File构造函数采用文件系统路径。您正在传递的内容:

  • 不是文件系统路径,因为路径没有类似file://http://content://的方案

  • 引用文件系统上不存在的目录

  

我在lib文件夹中有아현.csv

将其放入模块的src/main/assets/中。将AssetManager传递给您的modelPredict()方法,并在open()上使用AssetManager来获得InputStream,您可以将该传递给Scanner构造函数。通过在AssetManagergetAssets()之类的Context上调用Activity得到Service