我正在尝试阅读文件,但我得到了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);
}
答案 0 :(得分:1)
尝试使用' /'而不是' \ ,所以不需要转义任何使用的字符和路径字符串。