1
我尝试读txt文件,并追加到一个ArrayList。这似乎在与扫描线失败“java.io.FileNotFoundException:/raw/words.txt:打开失败:(没有这样的文件或目录)”。我试过了BufferReader方法,并且很少成功地改变文件的位置。为什么不识别文件?阅读txt文件列出的Android/FileNotFound
public void openFile(){
File file = new File("raw/words.txt");
ArrayList<String> names = new ArrayList<String>();
try{
Scanner in = new Scanner (file);
while (in.hasNextLine()){
names.add(in.nextLine());
}
}
catch (Exception e){
e.printStackTrace();
}
Collections.sort(names);
for(int i=0; i<names.size(); ++i){
System.out.println(names.get(i));
}
}
哪里是你的文件复制? – 2013-05-06 20:53:11
RES /生/ words.txt – ono 2013-05-06 20:55:19
刚刚发现这一点。它可以帮助http://stackoverflow.com/questions/5771366/reading-a-simple-text-file – ono 2013-05-06 20:55:37