Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a newline to a text file 1

Status
Not open for further replies.

albin1e4

IS-IT--Management
Nov 21, 2002
7
US
I am outputting user input from various JTextFields to a text file. This part works fine.

However, I need to tell the text file to move to a new line when additional user input is appended to the file. Just sending a '\n' isn't working. Right now I have one giant line of text in my file.

Any ideas?

Thanks, Brian
 
Try println() function of the PrintWriter... \n should work on *nix systems, but \r\n (i think) is the proper ascii chars for a newline in DOS based ASCII files. The println(String) will put the string into the filw with the proper newline chars for the OS.
 
println does indeed work

Why wouldn't the FileWriter class include a similar method? This class only includes a write method.

Anybody know the logic?

Brian
 
In java I/O the writer and readers use a decorator patter that is very useful, but it means that each class adds only a small amount of functionality... A file writter was designed to only the basics of file I/O, and the PrintWriter was given a few more methods so that I/O to text files would be easier. The logic for adding the \n or \r\n is fairly simple, but part of the basics to write to a file. Basically, he reason is because any one giver reader/writer/stream does the barest amount of work... The other thing that I would always have liked to see in the BufferedReader is a readInt, readFloat... but there not there either... So I used to do a lot of Integer.parseInt(), until I got ahold of an ExtractReader class from a Prof.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top