如何将文本文件内容导入Java应用程序中的JTextArea? [英] How to import a Text file content to a JTextArea in a Java application?
本文介绍了如何将文本文件内容导入Java应用程序中的JTextArea?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
应该是类似于以下代码:
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null); //用你的swing容器替换null
文件文件;
if(returnVal == JFileChooser.APPROVE_OPTION)
file = chooser.getSelectedFile();
}
JTextArea text = new JTextArea();
BufferedReader in = new BufferedReader(new FileReader(file));
String line = in.readLine();
while(line!= null){
text.append(line +\\\
);
line = in.readLine();
Luca
how to import a Text file content to a JTextArea in a Java application using JFileChooser?
解决方案
should be something like the following code:
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null); //replace null with your swing container
File file;
if(returnVal == JFileChooser.APPROVE_OPTION)
file = chooser.getSelectedFile();
}
JTextArea text = new JTextArea();
BufferedReader in = new BufferedReader(new FileReader(file));
String line = in.readLine();
while(line != null){
text.append(line + "\n");
line = in.readLine();
}
Luca
这篇关于如何将文本文件内容导入Java应用程序中的JTextArea?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文