chess: (the fire in her eyes masked the fear)
Have eaten whole 6-pack of scotch pancakes. Have still not finished Tick 7. BufferedReader's readLine method appears to be disagreeing with text files without a line break at the end. Naturally, this text file is one without a line break at the end. There are ways round this, but they are a Royal Pain in the Ass.

It is probably too late for me to be working. Have done no supervision work for tomorrow. This mildly annoys me, because I could have done with doing the maths work, as I'm currently on course for Failing Maths Horribly.

Date: 2004-05-09 05:00 pm (UTC)From: [identity profile] king-of-wrong.livejournal.com
Surely it's not all that difficult?


FileReader input; int c; String line="";
do {
try { c = input.read(); } catch (java.io.IOException e) { c = -1 }
if (c == -1) break;
if (c == (int)('\n')) break;
line = line + ((char)c);
} while (true);


PS - Watch for the evil blank line at #87, the spurious '\'s and the fact that the calendar line is broken for Easter term...

Date: 2004-05-10 04:04 am (UTC)From: [identity profile] jaq.livejournal.com
Even if you're reading by character, it's still worth wrapping the FileReader with a BufferedReader for efficiency.

But readLine() works fine for me on a file with no lineend at the end, so I'm not sure why it's a problem.
My example:
public static void main(String[] args) {
try {
BufferedReader rd = new BufferedReader(new FileReader("c:/working/testfile.txt"));
String line;
while((line = rd.readLine()) != null) {
System.out.println(line);
}
System.out.println("[EOF]");
} catch(Exception e) {
System.out.println("caught exception " + e.getMessage());
e.printStackTrace();
}
}

Profile

chess: (Default)
Michelle Taylor

January 2025

S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 2nd, 2026 01:39 pm
Powered by Dreamwidth Studios