1
如何在不使用CSVReader
的情況下將CSV文件導入JTable
。我目前正在使用掃描儀,但我一直在從CSV文件中獲取數據到Object[][]
。將CSV文件導入到無需CSVReader的JTable中
如何在不使用CSVReader
的情況下將CSV文件導入JTable
。我目前正在使用掃描儀,但我一直在從CSV文件中獲取數據到Object[][]
。將CSV文件導入到無需CSVReader的JTable中
你可以做這樣的事情。
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