在没有CSVReader的情况下将CSV文件导入JTable

时间:2016-09-22 01:18:26

标签: java swing jframe jtable

如何在不使用JTable的情况下将CSV文件导入CSVReader。我目前正在使用扫描仪,但我仍然坚持将CSV文件中的数据转换为Object[][]

1 个答案:

答案 0 :(得分:0)

你可以这样做。

ArrayList<String[]> data = new ArrayList<String[]>();
while( myScanner.hasNextLine()) {
    //get one row   
    String oneRow = myScanner.nextLine();
    //then split the line by comma
    String[] oneSplitRow = oneRow.split(",");
    //add your data to the arraylist
    data.add(oneSplitRow);
}
// now to make the Object[][]
Object[][] theData = new Object[data.size()][data.get(0).length];
// and here is where you can iterate through the data arraylist and put
//  the strings into theData 2d array
// ..... your code here