I have input file include these elements:
1,3,1
2,1,4
3,4,2
4,0,6
5,2,3
and I want to read this input file to get an output in my code so I did this main code:
public static void main(String[] args) throws IOException {
File File = new File("C:/Users/Princ/Downloads/testdata1 for SRTF.txt");
Scanner s = new Scanner(File);
int n = 5;
int a;
int b;
int c;
String data;
SJF ob = new SJF();
Process1 proc[] = new Process1[n];
while (s.hasNextLine()) {
for (int i = 0; n > i; i++) {
a = Integer.parseInt(s.nextLine());
b = Integer.parseInt(s.nextLine());
c = Integer.parseInt(s.nextLine());
proc[i] = new Process1(a, b, c);
}
ob.findavgTime(proc, n);
}
}
and then I get this error:-
Exception in thread "main" java.lang.NumberFormatException: For input string: "1,3,1"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at SJF.main(SJF.java:125)
What I have tried:
What should I fix in my code and what's wrong?