Article View: borland.public.jbuilder.java.language
Article #246Re: Writing plain text to file
From: 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.
>
Technical Details
Message-ID:
<44116ce5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<440c19e7$1@newsgroups.borland.com> <xn0ejejtb48ywr000-kdean@www.teamb.com> <440f475a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,7427db691bf1ff33 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII Date: Fri, 10 Mar 2006 13:14:52 +0100 From: Raul Lorenzo <rlorenb@agalisa.es> User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: Writing plain text to file References: <440c19e7$1@newsgroups.borland.com> <xn0ejejtb48ywr000-kdean@www.teamb.com> <440f475a$1@newsgroups.borland.com> In-Reply-To: <440f475a$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 81.32.15.229 Message-ID: <44116ce5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1141992677 81.32.15.229 (10 Mar 2006 04:11:17 -0700) Lines: 29 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail