0

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!!

5
Contributors
13
Replies
17
Views
9 Years
Discussion Span
Last Post by mayank.aga
0

so suppose i have

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

Is this correct?

0

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

0

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

0

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").

0

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.

0

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)

0

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");
0

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.

0

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.

0
File file=new File(rout);

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

		BufferedWriter out=new BufferedWriter(text);

                out.newLine();
                out.write("a String");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.