-1
JFileChooser jfch = new JFileChooser();
jfch.showOpenDialog(null);
File f = jfch.getSelectedFile();
StringBuilder sb = new StringBuilder();
try {
Scanner sc = new Scanner(f);
while (sc.hasNext()) {
sb.append(sc.next());
}
sc.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.print(sb.toString());
}
它有什麼問題?我選擇包含一些文本的文件,但仍然可以獲得可變的sb空白:/FileChooser和Scanner
什麼不工作?你可以說得更詳細點嗎? –