w*l 发帖数: 43 | 1 Hi,
I am using the following codes to create a file and put some strings (or some
other format data) into this file. I hope to save some extra strings into this
file when I run this program again. Of course, I don't want to delete the
original strings (or data). How can I finish this function?
File data_File = new File("image_data.txt");
FileOutputStream data_Stream = new FileOutputStream(data_File);
PrintWriter data_write_Stream = new PrintWriter(data_Stream);
data_write_Stream.print("abc");
Th | s***m 发帖数: 28 | 2
some
this
I got this somewhere on the web.
Open your file as RandomAccessFile, then go to the end of last line and start
writing.
java.io.RandomAccessFile data_file = new java.io.RandomAccessFile(fileName,
"rw");
data_file.seek(data_file.length());
data_file.write...(....);
data_file.close();
【在 w*l 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Hi, : I am using the following codes to create a file and put some strings (or some : other format data) into this file. I hope to save some extra strings into this : file when I run this program again. Of course, I don't want to delete the : original strings (or data). How can I finish this function? : File data_File = new File("image_data.txt"); : FileOutputStream data_Stream = new FileOutputStream(data_File); : PrintWriter data_write_Stream = new PrintWriter(data_Stream); : data_write_Stream.print("abc"); : Th
| u***************r 发帖数: 11227 | 3 I hope I have understood the problem right -- read the Javadoc for
FileOutputStream's constructor:
public FileOutputStream(String name,
boolean append)
throws FileNotFoundException
Creates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file
connection.
【在 w*l 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Hi, : I am using the following codes to create a file and put some strings (or some : other format data) into this file. I hope to save some extra strings into this : file when I run this program again. Of course, I don't want to delete the : original strings (or data). How can I finish this function? : File data_File = new File("image_data.txt"); : FileOutputStream data_Stream = new FileOutputStream(data_File); : PrintWriter data_write_Stream = new PrintWriter(data_Stream); : data_write_Stream.print("abc"); : Th
|
|