Hey Guys,

I am writing to a Text FIle in Java using FileOutputStream. But whatever I write is stored in the same line. What should I do if I want certain things to be stored in the next line. Basically, it is like inserting a new line into the file. Plzzzzzzz help me!!

Guys,

So many views but no replies......plzzzz help me fast....:|

same way you'd write a new line anywhere, by writing a newline character.

so suppose i have

FileOutputStream f = new FileOutputStream(""Data.txt");
f.write("Name");
f.newline();

Is this correct?

or f.write("\n"); I duno if what you wrote is correct, theres only one way test it!

Hi......apparently that does not work maybe coz im using fileoutputstream.......i dont no..........but please help me.

If you use BufferedWriter, which can be wrapped around a FileWriter, you can use newLine(). If you need to write the OS-specific line separator yourself, use System.getProperty("line.separator").

Again the prob.....System.getProperty("line.separator") does not work and i am not using BufferedWriter......can sm1 plss help me fr d FileOutputStream....DESPERATE NOW.

It is a valid system property that returns the appropriate system-specific line termination character. You still have to write it yourself though. And why can you not use BufferedWriter?

(Also, see the forum rules regarding "text-speak" and proper English)

There is a suggestion:

File file=new File(rout);
		FileWriter text=new FileWriter(file);
		BufferedWriter out=new BufferedWriter(text);

                out.newLine();
                out.write("a String");

Thanks.....bufferedWirter is working but the problem now is that every time i run the program it overwrites the tet file....does not store in continuation.

I have something that will make it write in continuation. Give me sometime to find it, because I have something else important to do now.

File file=new File(rout);

		FileWriter text=new FileWriter(file,[B]true[/B]);

		BufferedWriter out=new BufferedWriter(text);

                out.newLine();
                out.write("a String");

thnx man it works...ur gr8!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.