我试图读取一个文件,但我得到了一个NoSuchFileException。我知道我的代码可以工作,因为它可以在我创建的另一个程序中工作,但是它现在不工作了。是的,目录是正确的,在src文件夹中有一个文本文件。谁能告诉我怎么解决这个问题吗?
String[] words = new String[5];
Path file = Paths.get("H:\\Varsity work\\Java Programming\\Programs\\HangMan\\build\\classes\\HangMan.txt");
InputStream input = null;
try {
input = Files.newInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String s = null;
while((s=reader.readLine())!=null) {
System.out.println(s);
}
input.close();
} catch(Exception e) {
System.out.println(e);
}发布于 2016-09-24 12:39:28
尝试使用'/‘代替'\’,这样就不需要转义原来使用的任何字符和路径字符串。
https://stackoverflow.com/questions/39676342
复制相似问题