问题
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