我的代碼正道文件是繼::如何獲得Android中
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
我的文件夾中的資產/ MainMenu的/ readSourceFile.txt
,我已經嘗試這種::
private InputStream is;
try {
is = this.getResources().getAssets().open("mainmenu/readSourceFile.txt");
} catch (IOException e) {
e.toString();
}
我使用getAssets來訪問Android中的資產文件。但是,我怎麼能想,如果我用InputStream
是你所有的目錄都位於同一個項目?如果是這樣,只需將路徑設爲./assets/mainmenu/readSourceFile.txt .. – gks
@barssala你的文本文件在資產文件夾中? – vnshetty
當然,我的文本文件在資產/ mainmenu/readSourceFile.txt – barssala