好的,所以我有一个 x、y 和 z 坐标的电子表格。x 和 y 是整数,z 是浮点数。我想读取所有坐标,但是当我尝试运行它时出现错误。这是错误:
Exception in thread "main" java.lang.NumberFormatException: For input string: "XCoord"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source
这是我的代码:
BufferedReader br = new BufferedReader(new FileReader("./data/graphXYZ.csv"));
String dataRow = br.readLine(); // Read first line.
// The while checks to see if the data is null. If
// it is, we've hit the end of the file. If not,
// process the data.
int i = 0;
int xCoord, yCoord;
float zCoord;
while (dataRow != null) {
String[] dataArray = dataRow.split(",");
xCoord = Integer.parseInt(dataArray[0]);
yCoord = Integer.parseInt(dataArray[1]);
zCoord = Float.parseFloat(dataArray[2]);
for(String item:dataArray) {
System.out.print(xCoord + "\t");
System.out.print(yCoord + "\t");
System.out.print(zCoord + "\t");
}
System.out.println(); // Print the data line.
dataRow = br.readLine(); // Read next line of data.
}