I'm reading a text file into my program using a FileReader. I am attempting to get it to skip past newlines, \n and \r. When it skips a \r however it seems to skip the character after it as well, so the first character on every line is missing. If I println the skipped character (should be just a carriage return) it prints not only the carriage return but the first character of the next line as well:
The above (notice the commmented out \r bit) outputs not only a newline after the "ERROR", but the first character of the next line as well. If I uncomment the \r section of the while-loop it skips the first character as well as the carriage return.
I cant really see how this is possible and its really getting on my nerves. Any help would be much appreciated.
Dave.
Code:
int nextChar;
nextChar = fr.read();
...
while ((char)nextChar == '\n')
// || (char)nextChar == '\r')
nextChar = fr.read();
if ( (char)nextChar == '1'
|| (char)nextChar == '0'){
...
}else{
System.out.print("\nERROR: INVALID CHARACTER = " + (char)nextChar);
}
I cant really see how this is possible and its really getting on my nerves. Any help would be much appreciated.
Dave.