Android Studio Java File Not Found Exception

久未见 提交于 2019-12-11 06:08:32

问题


I tried every possible combination of paths that i could think of along with every possible location of the file. It simply does not stop going for the file Not Found exception (No file or Directory)

  try {
        String path = "D:\\Users\\[UserName]\\Desktop\\[NameofProject]\\app\\src\\main\\assets\\itemsURL";
        FileReader fileP = new FileReader(path);
        BufferedReader reader= new BufferedReader(fileP);
        for(String line; (line = reader.readLine()) != null; ) {
            filesArray.add(line);
        }
    } catch (FileNotFoundException e){
        e.printStackTrace();

Has anyone ever got this problem of, possibly, the most stubborn File Not Found exception?

java.io.FileNotFoundException: D:\Users\UserName]\Desktop\[NameofProject]\app\src\main\assets\itemsURL (No such file or directory)

File Format is like this:

 algae_banana
 boop_boop
 word_word_word
 bla_bla
 ...

回答1:


That's not how it works. You run the app on an emulator and there is no path D:/users/... on an android Device.

Try using he Assets folder and the getAssetManager()



来源:https://stackoverflow.com/questions/49078660/android-studio-java-file-not-found-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!