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