I want to read an integer value from a text file to an array. The code works fine if type the numbers in the .txt file. Afterwards i tried to copy integer values from excel to the text file and tried to read it. In this case i get the following error code.
[989 1042 1059 1067 1087 1098 1103 1110 1114 1131]
Exception in thread "main" java.lang.NumberFormatException: For input string:
"989 1042 1059 1067 1087 1098 1103 1110 1114 1131"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at readparetoapprox.readapproxset(readparetoapprox.java:83)
at DomSortepsilon.main(DomSortepsilon.java:11)
File fileText = new File(FileName);
Scanner sc = new Scanner(new BufferedReader(new FileReader(fileText)));
Scanner sc1 = new Scanner(new BufferedReader(new FileReader(fileText)));
String[] line1 = sc1.nextLine().trim().split(" ");
int rows = 2;
int columns = line1.length;
int [][] intarray= new int[rows][columns];
int x=0;
while(x<1) {
for (int i=0; i<intarray.length; i++) {
String[] line = sc.nextLine().trim().split(" ");
System.out.println(Arrays.toString(line));
for (int j=0; j<line.length; j++) {
paretofront[i][j] = Integer.parseInt(line[j]);
}
}
x++;
}
System.out.println(Arrays.deepToString(intarray));
I really have no idea why I receive the NumberFormatException error.
I´m really thankful for your help.
Greetings, Martin