我收到以下错误:
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
答案 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
构造函数。通过在AssetManager
或getAssets()
之类的Context
上调用Activity
得到Service
。