【发布时间】:2021-11-05 17:26:29
【问题描述】:
我是 java 新手,我的代码有点问题。没有错误等,它只是一直说进程完成但没有显示输出。我检查过的文件名是正确的。
导入 java.nio.file.; 导入 java.io.;
public class GuessingGame {
public GuessingGame() {
String filename = "C:\\Users\\angela\\Documents\\words.txt";
Path path = Paths.get(filename.toString());
try {
InputStream input = Files.newInputStream(path);
BufferedReader read = new BufferedReader(new InputStreamReader(input));
String word = null;
while((word = read.readLine()) !=null) {
System.out.println(word);
}
}
catch(IOException ex) {
}
}
public static void main (String[] args) {
new GuessingGame();
}
}
【问题讨论】:
-
不要错过这个例外。请打印以确认是否发生异常。
-
知道了,谢谢