【发布时间】:2016-09-22 01:18:25
【问题描述】:
如何在不使用CSVReader 的情况下将CSV 文件导入JTable。我目前正在使用扫描仪,但我一直无法将 CSV 文件中的数据导入Object[][]。
【问题讨论】:
如何在不使用CSVReader 的情况下将CSV 文件导入JTable。我目前正在使用扫描仪,但我一直无法将 CSV 文件中的数据导入Object[][]。
【问题讨论】:
你可以做这样的事情。
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
【讨论】: