Article View: borland.public.jbuilder.java.language
Article #17421Re: Problems writing newlines to a file
From: Graham Lovell
Date: Fri, 20 Nov 1998 00:00
Date: Fri, 20 Nov 1998 00:00
47 lines
2186 bytes
2186 bytes
I forgot to mention, to get it to compile, I included import java.io.*. This
then gave me a compile error for your code. I then changed the code to
OutputStreamWriter out = new OutputStreamWriter(...
It worked OK after that.
Graham Lovell wrote in message <7311k7$qo74@forums.borland.com>...
>Dear Matt,
>
>I tried your code, so that we could learn how to write to a file, which I
>hadn't been able to do so far, and it worked OK, including the new lines.
>(Thanks for the help, albeit this was not your immediate objective.)
>
>The new line came through OK as a newline, (extra newlines and text also
>worked OK) when read in both WordPad and in the Browser (I didn't bother to
>use an binary reader as it was working OK).
>
>Could this be a browser problem? I have had very variable results from
>different browsers. I used Internet Explorer 4.0 SP1, in testing this code.
>
>Graham
>
>Matt Butler wrote in message <72sc3h$14a13@forums.borland.com>...
>>I am having an problem with writing new lines to a file. I have tried
>>several different things, but to give you an idea here is the latest code
I
>>tried:
>>
>> String s = new String("test\n");
>> char[] buf = new char[s.length()];
>> s.getChars(0,s.length(),buf,0);
>> Writer out = new OutputStreamWriter(new
>>FileOutputStream("D:\\WWW\\Html\\User3.rpt"));
>> out.write(buf,0,s.length());
>> out.flush();
>>
>>What is happening is that the \n is coming out as an unprintable character
>>rather than a newline. It works fine if sent to system.out rather than a
>>file.
>>
>>Any ideas?
>>
>>Thanks,
>> Matt
>>
>>
>
>
Technical Details
Message-ID:
<73358r$svc2@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<72sc3h$14a13@forums.borland.com> <7311k7$qo74@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1b6563995c977abb X-Google-Attributes: gidf74b3,public From: "Graham Lovell" <glovell@pennantsw.com.au> Subject: Re: Problems writing newlines to a file Date: 1998/11/20 Message-ID: <73358r$svc2@forums.borland.com> X-Deja-AN: 413792581 References: <72sc3h$14a13@forums.borland.com> <7311k7$qo74@forums.borland.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: Pennant Software Pty Ltd Newsgroups: borland.public.jbuilder.java.language