由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - How to append something on a file?
相关主题
急问如何append double 数据到txt文件新手问个简单问题 System.out
How to write a file to the same directory of the class file?Help on file locking
which one should I close?ERROR!java.io.RandomAccessFile.readInt
[转载] create gif/png image in C or javajava string stream
求Java8大牛们帮忙看看这个multithread的面试题。 (转载)File generated by Java cannot be read by Android App
问一个blocking IO的程序请问StringBuffer的OutofMemory问题
Re: how to write a string to a new file我自己编了个Java面试题
Re: RandomAccessFile和FileOutputStream有什么Re: how to upload a local file to web server?
相关话题的讨论汇总
话题: file话题: data话题: stream话题: append
进入Java版参与讨论
1 (共1页)
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 的大作中提到】
: 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 的大作中提到】
: 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

1 (共1页)
进入Java版参与讨论
相关主题
Re: how to upload a local file to web server?求Java8大牛们帮忙看看这个multithread的面试题。 (转载)
how to open pipe files in java问一个blocking IO的程序
编程新人求助—死循环了Re: how to write a string to a new file
包子答谢--请教高手:streaming data to appletRe: RandomAccessFile和FileOutputStream有什么
急问如何append double 数据到txt文件新手问个简单问题 System.out
How to write a file to the same directory of the class file?Help on file locking
which one should I close?ERROR!java.io.RandomAccessFile.readInt
[转载] create gif/png image in C or javajava string stream
相关话题的讨论汇总
话题: file话题: data话题: stream话题: append