さて、x、y、z 座標のスプレッドシートがあります。x と y は整数で、z は float です。すべての座標を読み取りたいのですが、実行しようとするとエラーが発生します。これはエラーです:
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.
}