Thread View: borland.public.jbuilder.java.language
4 messages
4 total messages
Started by Raul Lorenzo
Mon, 06 Mar 2006 11:19
Writing plain text to file
Author: Raul Lorenzo
Date: Mon, 06 Mar 2006 11:19
Date: Mon, 06 Mar 2006 11:19
25 lines
1347 bytes
1347 bytes
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
Author: Kevin Dean [TeamB]
Date: Mon, 06 Mar 2006 12:54
Date: Mon, 06 Mar 2006 12:54
18 lines
1493 bytes
1493 bytes
Raul Lorenzo wrote: >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. http://www.datadevelopment.com/ NEW WHITEPAPERS Team Development with JBuilder and Borland Enterprise Server Securing Borland Enterprise Server http://www.datadevelopment.com/papers/index.html Please see Borland's newsgroup guidelines at http://info.borland.com/newsgroups/guide.html
Re: Writing plain text to file
Author: Shankar Unni
Date: Wed, 08 Mar 2006 21:06
Date: Wed, 08 Mar 2006 21:06
25 lines
1849 bytes
1849 bytes
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 naked
"\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.
Re: Writing plain text to file
Author: Raul Lorenzo
Date: Fri, 10 Mar 2006 12:14
Date: Fri, 10 Mar 2006 12:14
29 lines
1888 bytes
1888 bytes
Thanks a lot, this is what I was searching.
Shankar Unni escribi๏ฟฝ:
> 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 naked
> "\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.
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads