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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can format entry in text file?

Status
Not open for further replies.

papaboy2

MIS
Jan 28, 2003
52
0
0
PH
hi, i would like to ask how can i format the data i will append in a text file, like when appending new data it will be in the next line of the file?, my code below concats the first and second text i inserted, thank you very much!

BufferedWriter out = new BufferedWriter(new FileWriter("guestbook.txt", true));
out.write("First LINE");
out.write("Second LINE");
out.close();
} catch (IOException e) {
 
out.write("First LINE");
out.newLine();
out.write("Second Line");
out.newLine();


Or use a PrintWriter :

PrintWriter pw = new PrintWriter(new FileOutputStream("file.txt", true));
pw.println("First line");
pw.println("Second line");


--------------------------------------------------
Free Database Connection Pooling Software
 
You can also use the escape chars, but remember that unix/Linux use just '\n' for a line return and windows requires '\n' AND '\r'.

Code:
\n   newline
\r   return
\t   tab
\\   \
\"   "
\'   '
\a   bell char
\0   (that's a zero not an o) null char

PrintWriters make things a lot easier... I would push you in that direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top