我在使用FileInputStream
对象读取文件时遇到问题。我想打开的文件存在(我用同一个应用程序创建了它,我可以用我设备上的文件管理器看到它)。这就是方法:
public String readFile(String name) {
try {
FileInputStream fis;
String res = "", read;
File tmp = new File(directory, name);
fis = new FileInputStream(tmp);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader buffered_reader = new BufferedReader(isr);
read = buffered_reader.readLine();
while (read != null) {
res = res + read;
Log.i("AAAAAAAAAAAAAAAAA", "letto"+read);
read = buffered_reader.readLine();
}
isr.close();
fis.close();
return res;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i("AAAAAAAAAA", "Letto un cazzo");
return null;
}
其中目录变量声明为:
private static File directory;
存储应用程序目录的静态对象文件。问题出在哪里?
Logcat 说
打开失败的enoent(没有这样的文件或目录)
在行
fis = new FileInputStream(tmp);