Jon
Greg Charles wrote:1. Although 'udddd' is a valid way to specify unicode characters, the two exceptions are carriage returns ('\u000d') and line feeds ('\u000a'). These should be specified as '\r' and '\n' respectively.
Jon Camilleri wrote:I'm trying to write to an existing log file, and I understand (by reading a few posts) that there is no way to append to an existing text file.
Ooops... the problem was Notepad It wasn't reading the CRs somehow. Should have known better
Well, not quite. I'm still unsure about how to declare a Unicode character as a char type. The single quotation marks don't seem to compile:
Err:
C:\Users\Administrator\Desktop\test.java:57: illegal line end in character literal
char cr = '\u000d';
^
1 error
Tool completed with exit code 1
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:And for the record, my failed post:
----
Jon Camilleri wrote:I'm trying to write to an existing log file, and I understand (by reading a few posts) that there is no way to append to an existing text file.
Sure there is. Just check all of the FileWriter constructors. FileOutputStream has the same feature.
how about \r\n? Or even better: System.getProperty("line.separator");
Ooops... the problem was Notepad It wasn't reading the CRs somehow. Should have known better
Notepad has problems with all line ending sequences that are not exactly \r\n. That includes \r and \n.
Well, not quite. I'm still unsure about how to declare a Unicode character as a char type. The single quotation marks don't seem to compile:
Err:
C:\Users\Administrator\Desktop\test.java:57: illegal line end in character literal
char cr = '\u000d';
^
1 error
Tool completed with exit code 1
The problem is that unicode sequences are actually interpreted by the compiler. '\u000d' is a carriage return, so the compiler sees the source code as this:
Similarly, '\u000A' is also not allowed - that's a line break. That's what \r and \n are for.
---
Guess most of us had the same idea
Jon
Don't get me started about those stupid light bulbs. |