我的代码如下:
Scanner sc = null;
try {
sc = new Scanner(new File("assets/mainmenu/readSourceFile.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println(e1.toString());
e1.printStackTrace();
}
然后,logcat显示异常java.io.FileNotFoundException
我该如何找到我的文件?我尝试了:
sc = new Scanner(new File("mainmenu/readSourceFile.txt"));
然而,它仍然抛出FilenotFoundException
我的文件在assets/mainmenu/readSourceFile.txt文件夹中
我已经尝试过这个:
private InputStream is;
try {
is = this.getResources().getAssets().open("mainmenu/readSourceFile.txt");
} catch (IOException e) {
e.toString();
}
我使用getAssets来访问Android中的assets文件。但是,如果我使用 InputStream
,该如何读取文本文件呢?
java.io.FileNotFoundException:/./asset/mainmenu/readSourceFile.txt
。 - barssala