我正在嘗試讀取存儲在res/raw下的文本文件。我無法解決爲什麼文件無法打開並將內容讀入textArea「usersTextArea
」。系統只輸出System.out.println("file could not open");
。我不認爲文件路徑不正確。任何人都知道可能會導致問題的原因?謝謝。Android Java從res/raw中讀取文本文件,未找到文件錯誤
public void readFile()
{
String path = "android.resource://" + getPackageName() + "/" + R.raw.users;
try
{
Scanner s = new Scanner(new File(path));
while (scan.hasNext())
{
String data = scan.next();
usersTextArea.append(data);
}
scan.close();
}
catch(Exception error)
{
System.out.println("file could not open");
}
}