سلام
من java زیاد بلد نیستم
این مثال رو می زارم شاید به دردتون بخوره
public FileOutputStream(String name, boolean append)
throws IOException
in Java 1.0, however, you must use the java.io.RandomAccessFile class that lets you read and write bytes from arbitrary locations in a file. this class implements DataInput and DataOutput so you have all the methods of DataInputStream and DataOutputStream available to you.
To create a new random access file pass the name of the file and the mode to the constructor. The mode is either "r" (read-only) or "rw" (read and write). The length() method returns a long that tells you how many bytes there are in a file and the seek(long p) method lets you position the file pointer at a particular point in the file. Thus to start writing at the end of a RandomAccessFile raf, you first raf.seek(raf.length()). The following example demonstrates by appending the string "Kilroy was here!" to every file specified on the command line.
(Java FAQ:found on the web at:http://sunsite.unc.edu/javafaq/javafaq.html)
// By:
//**************************************
//
import java.io.*;
class AppendToAFile {
public static void main (String args[]) {
for (int i = 0; i < args.length; i++) {
//First open the file you want to append
// to
try {
RandomAccessFile raf = new RandomAccessFile(args[i], "rw");
// Position yourself at the end of the f
// ile
raf.seek(raf.length());
// Write the String into the file. Note
// that you must
// explicitly handle line breaks.
raf.writeBytes("\nKilroy was here!\n");
}
catch (IOException e) {
System.out.println("Error opening file: " + e);
}
}
}
}
منبع : http://www.pscode.com/vb/scripts/Sho...d=258&lngWId=2