dcsimg
write to file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   yu_yu
Posted On:   Thursday, February 7, 2002 11:32 PM

Hi all, how to write to file let say try.txt but what i want is write line by line everytime user make an input example user type "aaaa" it will be inserted to try.txt (first line) after that user type again "bbbb" than it will be inserted into try.txt (second line) without overwrite the first line
pls help me

Re: write to file

Posted By:   Christopher_Schultz  
Posted On:   Friday, February 8, 2002 05:30 AM

If you are using the same FileWriter (or whatever) without moving the file pointer, then you will just keep appending.



One option is to create a new FileWriter for each time you want to write to the file. This will overwrite the file every time.



Another option is to use a RandomAccessFile and set the file pointer (using seek) to zero before writing your String.



I'm not sure why you would want to do what you are doing, but that's how to do it.



-chris
About | Sitemap | Contact