How to append a new line to a File/FileConduit?

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Jan 13 07:26:05 PST 2009


On Tue, Jan 13, 2009 at 1:42 AM, Sam Hu <samhu.samhu at gmail.com> wrote:
> Hello everyone!
>
> Just found I can not append a new line to a file when writing data to a File or FileConduit instance.
>
> File file=new File("myfile.txt");
> myfile.append("This is line 1");
> myfile.append("This is line 2");
> About code just generate "This is line 1This is line 2"
> I tried below code but all the same:
> myfile.append("\n\nThis is line 1\n\n");
> myfile.append("\n");
> myfile.append("This is line 2");

If you're on Windows, the line ending convention is "\r\n", not just
"\n", so you could try that.

Alternatively, use a Print/FormatOutput (depends on whether you're
using 0.99.7 or HEAD).


More information about the Digitalmars-d-learn mailing list