Board index » jbuilder » Writing plain text to file

Writing plain text to file


2006-03-06 07:19:23 PM
jbuilder16
Hi,
I have this piece of code to write a String to a file:
static public void setContents(File aFile, String aContents) throws
FileNotFoundException, IOException
{
Writer output = null;
try
{
output = new BufferedWriter( new FileWriter(aFile) );
output.write( aContents );
}
finally
{
if (output != null)
output.close();
}
}
But the file, looks like: (Some problem with \n) (How to solve it)
nullu0Inicializando REMu0Inicializando IU Pluginu0Ini
 
 

Re:Writing plain text to file

Raul Lorenzo wrote:
Quote
I have this piece of code to write a String to a file:
Try using PrintWriter and the println() method.
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/
NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
www.datadevelopment.com/papers/index.html
Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html
 

Re:Writing plain text to file

Kevin Dean [TeamB] wrote:
Quote
Raul Lorenzo wrote:

>I have this piece of code to write a String to a file:

Try using PrintWriter and the println() method.

To expand on that: you need to write out your text line by line, with
println(). If you simply concatenate a bunch of lines with "\n" for
newlines, they won't get translated to the platform newline (\r\n)
automatically.
The other alternative is that in your code, instead of using a {*word*192}
"\n" when concatenating your strings, you use the platform line
separator property:
String platformNewLine = System.getProperty("line.separator");
String output =
"this is the first line" + platformNewLine +
"this is the second line" + platformNewLine +
...;
And now you can write out your string using your original code.
 

{smallsort}

Re:Writing plain text to file

Thanks a lot, this is what I was searching.
Shankar Unni escribi?
Quote
Kevin Dean [TeamB] wrote:
>Raul Lorenzo wrote:
>
>>I have this piece of code to write a String to a file:
>
>Try using PrintWriter and the println() method.
>

To expand on that: you need to write out your text line by line, with
println(). If you simply concatenate a bunch of lines with "\n" for
newlines, they won't get translated to the platform newline (\r\n)
automatically.

The other alternative is that in your code, instead of using a {*word*192}
"\n" when concatenating your strings, you use the platform line
separator property:

String platformNewLine = System.getProperty("line.separator");

String output =
"this is the first line" + platformNewLine +
"this is the second line" + platformNewLine +
...;

And now you can write out your string using your original code.