I am reading some data from a file and each line is assigned to one cell of the String array. For some reason when I try to print the array after reading the file(lines 8-10), I get nothing printed. When I print the line in the While loop(line 5) I get the line printed correctly.
1: int count = 0;
2: String[] s = new String[300];
3: while(!StdIn.isEmpty()) {
4: s[count]=StdIn.readLine();
5: System.out.println(s[count]);
6: count++;
7: }
8: for(int i=0;i<count;i++) {
9: System.out.println(s[i]);
10: }
Same code using Scanner:
Scanner in = new Scanner(System.in);
int count = 0;
String[] s = new String[300];
while(in.hasNextLine()) {
s[count]=in.nextLine();
System.out.println(s[count]);
count++;
}
for(int i=0;i<count;i++) {
System.out.println(s[i]);
}
I can't figure out what's wrong with my code.
Thanks in advance.
EDIT: When the last line has been read, the in.hasNextLine() is not returning anything. It got stuck at the count++. See photo -> DEBUGGER