I seem to be getting java.util.InputMismatchException when reading from a file. The file is just an array of numbers
Please advise.
package assignment1;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class Question4 {
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile =
new Scanner(new FileReader("glassdatatxt.txt"));
Double [][] glassdata = new Double[214][11];
for(int row = 0; row < glassdata.length; row++)
{
for(int col = 1; col < glassdata[row].length; col++)
{
glassdata[row][col] = inFile.nextDouble();
}
}
for(int row = 0; row < glassdata.length; row++)
{
for(int col = 1; col < glassdata[row].length; col++)
{
System.out.print(glassdata[row][col] + " ");
}
System.out.println();
}
}
}
It was not reading the space character correctly. Initially I have commas in between the numbers. I replace the commas incorrectly. I got it to work now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.