【发布时间】:2020-06-20 10:05:56
【问题描述】:
目前正在处理一个导入 .csv 文件(21 行,20 列)的项目,将其捕获到一个数组中,然后在电子表格中打印一个特定的单元格...目前遇到一个导致输出的问题为 20 行和一列,为“null” 除了输出中的第二行似乎是文件中的最后一行、第二列单元格。 Null 是怎么回事,为什么要拉最后一行数据?谢谢,伙计们/姑娘们的任何意见。
public class cvsPull {
public String[][] myArray;
String csvFile = "Crime.csv";
public Class csvPull() {
myArray = new String[20][20];
try {
s = new Scanner (new BufferedReader(new FileReader(csvFile)));
while (s.hasNext()) {
int theRow = 1;
int theCol = 0;
InputLine = s.nextLine();
String[] InArray = InputLine.split(",");
for (String InArray1 : InArray) {
myArray[theRow][theCol] = InArray1;
theCol++;
if (theCol==20) {
theCol=0;
theRow++;
}
// System.out.println(myArray[theRow][theCol]);
}
}
for (String[] theString : myArray) {
System.out.println(theString[1]);
}
} catch (IOException ioe) {
System.out.println("incorrect file name" + ioe.getMessage());
}
}
【问题讨论】:
标签: java arrays csv multidimensional-array input