Android 成功创建文件后未找到FileNotFound
我已通过以下方式下载了csv文件信息文件:Android 成功创建文件后未找到FileNotFound,android,exception-handling,Android,Exception Handling,我已通过以下方式下载了csv文件信息文件: File file = new File(context.getFilesDir().getAbsolutePath()+ "/data2.csv"); // File file = new File("data2.csv"); try { ftp.connect("x.x.x.x"); ftp.login("xx", "xx");
File file = new File(context.getFilesDir().getAbsolutePath()+ "/data2.csv");
// File file = new File("data2.csv");
try {
ftp.connect("x.x.x.x");
ftp.login("xx", "xx");
ftp.changeWorkingDirectory("/");
ftp.enterLocalPassiveMode();
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
OutputStream outputStream = null;
boolean success = false;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file));
success = ftp.retrieveFile("data.csv", outputStream);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
之后,我检查了我的应用程序ddms,文件data2.csv就在那里
然后我就想把它打开
CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open(context.getFilesDir().getAbsolutePath()+File.separator+"data2.csv")));
几次尝试后,它抛出“filenotfoundexception”。我该怎么办?您应该使用
新文件输入流(…)
而不是getAssets()。打开(…)
此行不正确:
CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open(context.getFilesDir().getAbsolutePath()+File.separator+"data2.csv")));
将其更改为:
CSVReader reader = new CSVReader(new InputStreamReader(context.getFilesDir().getAbsolutePath()+File.separator+"data2.csv")));
构造函数InputstreamReader(字符串)未定义。是。。使用此新文件输入流(新文件(context.getFilesDir().getAbsolutePath()+File.separator+“data2.csv”);您好,从ddms中可以看到,从FTP下载保存在文件路径中的文件只有-rw------权限。你认为那会阻止我读书吗?