我正在尝试读取存储在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");
}
}