android - Opencsv 中的 java.io.FileNotFoundException
问题描述
我想读一个 CSV 文件。我尝试在 Android 应用程序中读取 CSV 文件
public float modelPredict(String StationNM, int day, int hour, int minute) {
int[] model = new int[0];
try {
File csvfile = new File(Environment.getExternalStorageDirectory() + "/"+StationNM+".csv");
CSVReader reader = new CSVReader(new FileReader("csvfile.getAbsolutePath()"));
// CSVReader reader = new CSVReader(new FileReader(StationNM+".csv"));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
model = new int[nextLine.length];
for (int i=0; i<nextLine.length; i++) {
model[i] = Integer.parseInt(nextLine[i]);
}
} catch (Exception e) {
e.printStackTrace();
//Toast.makeText(this, "The specified file was not found", T oast.LENGTH_SHORT).show();
}
但我得到一个例外:
/System.err: java.io.FileNotFoundException: csvfile.getAbsolutePath() (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:231)
at java.io.FileInputStream.<init>(FileInputStream.java:165)
我该如何解决?
我不知道“csvfile.getAbsolutePath()”中的输入是什么
在我的存储库中是https://github.com/Lay4U/CapstOne/tree/master/SC/MySubwayProject
解决方案
代替:
CSVReader reader = new CSVReader(new FileReader("csvfile.getAbsolutePath()"));
和:
CSVReader reader = new CSVReader(new FileReader(csvfile));
推荐阅读
- c - 使用小批量时如何更新权重?
- php - Do ints differ from strings when type hinting in PHP
- openshift - Openshift oc cluster up 无法连接到 127.0.0.1:8443
- spring - @SpringBootTest 在什么情况下需要可选的“类”元素?
- android - Flutter - ListView 中的交互式 ListTile
- angular - 动态创建组件并导航到它
- c++ - Sfml网络,SocketSelector成员函数isReady不能正常工作
- laravel - Laravel Excel 导出 - 从视图不起作用
- javascript - 与绑定进度功能一起使用时,Angular Bootstrap Progressbar 未更新
- linux - crontab 中的 OpenVPN 问题