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

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