这可能是一个简单的问题。扫描文本文件时遇到问题。我想扫描一个文本文件并在JOptionPane中显示消息。它扫描,但它只显示我的文本文件的第一行,然后停止忽视其他行。如果我能得到一点帮助。非常感谢你!这里是我的代码:扫描文本文件
File file = new File("src//mytxt.txt");
try{
Scanner input = new Scanner(file);
while(input.hasNext()){
String line = input.nextLine();
JOptionPane.showMessageDialog(null, line);
return;
}
input.close();
}
catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null, "File not found");
}
}
你觉得'return'的确如此,你为什么这么认为? –
返回??真的 –
如果我删除返回它显示新的JOptionPane中的每一个新行,我不希望它那样。我想要在一个JOptionPane中扫描整个文本文件。 – Pepka