|
Replies:
7
-
Last Post:
Oct 29, 2004 2:10 AM
by: monika_krug
|
|
|
|
|
|
|
FileWriter.writeln(String)
Posted:
Oct 26, 2004 1:58 AM
|
|
|
I would like a method in FileWriter that adds the system-dependent linebreak character after the line: .writeln(String). As FileWriter inherits its write methods from OutputStreamWriter and Writer, it should probably be defined in one of these.
Yeah, I could use PrintWriter, but there are more differences to PrintWriter than that it has println methods, e.g. it does not throw Exceptions, but sets an error flag, so I would really prefer if FileWriter had a writeln method.
So far I do write(String + BR) and have static String BR = System.getProperty("line.separator"); in the class. It's okay, but a writeln method would be nicer.
Monika.
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 26, 2004 2:10 AM
in response to: monika_krug
|
|
|
No, you should wrap FileWriter in a BufferedWriter which already has a newLine() method. Perhaps some writeln convenience methods should be added to BufferedWriter.
|
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 26, 2004 3:25 AM
in response to: mthornton
|
|
|
So, add writeln to java.io.Writer, then both BufferedWriter and FileWriter will have it.
Monika.
|
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 26, 2004 4:05 AM
in response to: monika_krug
|
|
|
Have you noticed that since 1.5 Writer has mentioned chained method Writer append(CharSequence csq) & friends?
Still, java.io.Writer is the best place for something like writeln() or newLine()...
|
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 26, 2004 2:11 AM
in response to: monika_krug
|
|
|
I think it is much better to use BufferedWriter which has newLine() method doing what you need. And it performs much better of course. However, println() still missing
Anyway, I would prefer some implementation that behaves the similar way as StringBuffer or StringBuilder and allows chained calls (append().append().append()...)
|
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 26, 2004 2:22 AM
in response to: patrikbeno
|
|
|
Yes, and use this 'pattern' anywhere it is possible, for example Collection's add().add() ... Map's put().put()... etc.
|
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 28, 2004 4:05 AM
in response to: monika_krug
|
|
|
What about PrintWriter?
|
|
|
|
|
|
|
|
Re: FileWriter.writeln(String)
Posted:
Oct 29, 2004 2:10 AM
in response to: ronaldtm
|
|
|
I mentioned in my original post why I do not want to use it.
Monika.
|
|
|
|
|