Perry Smith

Java Questions & Answers

Home / Java Q & A Archive Page 3 / Java Q & A Archive

Appending a line to an existing file?
Monday, 01-Feb-99 21:18:23

12.73.183.218 writes:

Hi-I'm just learning JAVA, and have a class assignment where we have to prompt for a string, and write it to the end of an existing file. What can I use?

Thanks

Lisa


Responses
Re: Appending a line to an existing file?
Tuesday, 02-Feb-99 00:11:58 152.169.251.224 writes:

The java.io.RandomAccessFile class will probably come in handy with it's "long length()" and "void seek(long)" and "writeBytes(String)" methods. I have a vague feeling that I'd heard there was some bad consequence of using the "writeBytes(String)" method, but I can't remember what it was. Maybe it's nothing, but if you encounter strange problems, then that's probably a good place to start looking. Avoid the possible "off-by-one-error" that a beginner might run into with trying to use "rafSomeFile.seek(rafSomeFile.length())".

MikeD


Re: Appending a line to an existing file?
Friday, 05-Feb-99 02:12:40

203.129.225.221 writes:

Hi, U can use outputstream class in which u create a temparary file open it.Dump all the contents of the existing file.Then u can put the user prompted string in the temparary file.Then delete the previously exsting file.and rename the temparary file to that file Anand

Anand Gore


Home / Java Q & A Archive Page 3 / Java Q & A Archive