🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #243

Re: Writing plain text to file

#243
From: Shankar Unni
Date: Wed, 08 Mar 2006 21:06
25 lines
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.
Technical Details
Message-ID: <440f475a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!news2.volia.net!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <440c19e7$1@newsgroups.borland.com> <xn0ejejtb48ywr000-kdean@www.teamb.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,7427db691bf1ff33
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 08 Mar 2006 13:06:24 -0800
From: Shankar Unni <shankarunni@netscape.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0
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>
In-Reply-To: <xn0ejejtb48ywr000-kdean@www.teamb.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 68.120.146.125
Message-ID: <440f475a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1141851994 68.120.146.125 (8 Mar 2006 13:06:34 -0700)
Lines: 26
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!news2.volia.net!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail