如何将文本文件中的数据导入jtable?

时间:2017-06-05 04:02:57

标签: java

如何将文本文件的内容显示为jTable?

String fileName = "/Users/JJ/Desktop/SSD Text.txt";

// This will reference one line at a time
String line = null;

try {
    // FileReader reads text files in the default encoding.
   FileReader fileReader = new FileReader(fileName);

    // Wraps FileReader in BufferedReader.
    BufferedReader bufferedReader = 
        new BufferedReader(fileReader);
    int i = 0;
    int x= 0;
    Object[][] myarray = new String [4][100];
    while((line = bufferedReader.readLine()) != null) {
      x=0;
        for (String retval: line.split (",")) {
        myarray[x][i]=retval; 
        }

1 个答案:

答案 0 :(得分:1)

以下代码从文件中读取数据并将其放在JTable的第1列中。我希望这可以帮到你。

For the solution please visit