读取jtable中的文件 [英] Read a file in a jtable
本文介绍了读取jtable中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的代码:
private void jTable4MouseClicked(java.awt.event.MouseEvent evt) {
if (evt.getClickCount() == 1) {
System.out.println("clicked");
int row = jTable4.getSelectedRow();
if (row != -1) {
String firstColumnValue = jTable4.getModel().getValueAt(row, 0).toString();
String secondColumnValue = jTable4.getModel().getValueAt(row, 1).toString();
jTextAreaMainFileHighlight.setText(firstColumnValue); // just show name of a file
jTextAreaComparingFileHighlighter.setText(secondColumnValue); // just show name of a file
}
您知道,jtabel包含文件名.如何将该文件读取到然后显示在jTextArea中
You know, the jtabel is contains a name of file. How to read that file to and then show in jTextArea
推荐答案
这是读取Java文件的基础.无论如何读取文件(在jtable中给出的名称)并显示文件的内容,您都可以使用以下命令
This is a basic of java file reading .Anyway to read the a file (name given in jtable) and to display the content of the file you can use following
BufferedReader br = null;
try {
String str;
br = new BufferedReader(new FileReader(firstColumnValue));
while ((str = br.readLine()) != null) {
System.out.println(str);
jTextAreaMainFileHighlight.setText(str);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
这篇关于读取jtable中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文