我正在开发一个简单的 Android 应用程序,需要文本文件访问!我得到filenotfoundexception
即使我在文件构造函数中指定了文件的绝对路径。我的代码是
`File fr = new File("C:/mywork1/Dictionary/src/com/praveen/dictionary/vsn.txt");
System.out.println(fr.getAbsolutePath());
Scanner bb = new Scanner(fr);
System.out.println(fr.exists());
while((strf = bb.nextLine()) != null)
{...
之前的一些问题的答案建议使用 AssetsManager
反而。我试过了。
AssetManager assetManager = Context.getAssets();
InputStream in = null;
in = assetManager.open("vsn.txt");
我收到此代码的错误是
"cannot make static reference to a non static variable"
在第一行。请帮我解决这个问题..我什至不能使用 throws 子句,因为我正在使用 onCreate 方法!我更改了运行配置中的设置,以便当前工作目录将包含我的文本文件。谢谢
最佳答案
Android 设备不会保存或读取 C: 目录中的文件。
您必须将其移至项目内的 Resources 文件夹中并以这种方式包含它。
关于java - java中的FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17018720/