File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Writing into a file without printing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing into a file without printing "\n" in seperate lines" Watch "Writing into a file without printing "\n" in seperate lines" New topic

Writing into a file without printing "\n" in seperate lines

Monish Das

Joined: Sep 28, 2006
Posts: 4
Hello Friends,
I am facing an issue that while writing to the file i am able to print "\n" for getting all the files in seperate line.But i want to avoid this i.e. i want to write in separate line but "\n" shouldnt be printed.
I am using bf.newLine() for the separate lines...
How can i avoid this?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14917

I don't know what you mean by "bf.newLine()". Is "bf" a variable in your program? If so, what's the type?

Different operating systems use different sequences of characters to represent newlines in text files. For example, Windows uses a sequence of two characters: carriage return and line feed (ASCII codes 10 and 13). Unix computers use just one character: line feed.

In Java, if you want to write a program that uses the line ending sequence of the operating system you're running it on, you should get the system property named "line.separator" instead of directly putting codes line "\n" in the program.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Writing into a file without printing "\n" in seperate lines
jQuery in Action, 3rd edition