Writing multiple variables to file

Hey guys, im wondering if anyone can help me with writing multiple variables to one .txt on the HDD. Ive already programmed the following:

BufferedWriter writePaid =new BufferedWriter(new FileWriter("C:\\Debt Logger\\Users\\" + user + "_log.txt"));

writePaid.write(paidAmount);

writePaid.flush();

writePaid.close();

but with that i can only write one variable value to the file... is there a way to have maybe line 1 be value of paidAmount, line 2 be value of debtAmount and then have BufferedReader read from which ever of the 2 lines i need it to? Thanks in advance for the help.

[735 byte] By [HDL_CinC_Dragona] at [2007-10-2 20:14:11]
# 1
If you want to write more stuff, don't close it yet.If you want to write a line-based text file use PrintWriter's println method. http://java.sun.com/docs/books/tutorial/essential/io/index.html
jverda at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...
# 2
Why can you only write 1 variable to the file? Why can't you perform multiple 'write()s'?Once you read in a line, examine its content, discard it if it doesn't meet your requirements or process it if it does.Good luck.
filestreama at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...
# 3

> then have BufferedReader read from which ever of the

> 2 lines i need it to?

No. You'd have to read the file line by line and just ignore the first N lines that you don't want to deal with.

Or, if a line will be a fixed length, then you could use RandomAccessFile to jump immediately to a specific byte position in the file.

jverda at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...
# 4
Also, write(paidAmount) might not do what you probably think it does, depending on what type paidAmount is and what you're trying to do.
jverda at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...
# 5
What im trying to do is save multiple Integer Variables to one .txt file. Ill try what you guys have told me but any more feedback would also be nice :)Im going to try them now.
HDL_CinC_Dragona at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...
# 6

Ok i just got my program to read each line! Thanks guys!

Now for getting it to write line by line...

Is there a way to do that without using PipedWriter?

so if i had these variables for example:

int bunnies = 12, birds = 18, snakes = 6, dogs = 23;

how would i get it to write to the file like this:

12

18

6

23

even if i have to write them as Strings instead of Integers thats not problem because i could just Parse them into Integers when i read them in...

HDL_CinC_Dragona at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...
# 7
I GOT IT WORKING! Thank you everyone so MUCH! i now have it writing line by line and reading line by line! thank you very much for your help!
HDL_CinC_Dragona at 2007-7-13 22:56:22 > top of Java-index,Java Essentials,New To Java...