I have this code...
try{
FileReader fread = new FileReader(new File("testfile"));
int y = 0;
while (fread.ready()){
char path = (char)fread.read();
System.out.println(path);
if (path == '\n'){
y++;
}
}
System.out.println("Newlines: " + y);
}
catch (Exception e){
System.out.println(e.getMessage());
}
...and a file called testfile containing the following information...
ABC
...and when I run the program it prints out that the file contains one newline. Why is that? I simply cannot find the reason why, having read the Oracle documentation. My problem is easily solved by subtracting one from y, but I am not satisfied with that. This problem drives me crazy since I have no clue where the newline comes from.