import java.io.*;
public class appendtext {
public static void main(String args[]){
try {
PrintStream out =
new PrintStream(new AppendFileStream("myfile"));
out.print("A new line of text");
out.close();
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}
class AppendFileStream extends OutputStream {
RandomAccessFile fd;
public AppendFileStream(String file) throws IOException {
fd = new RandomAccessFile(file,"rw");
fd.seek(fd.length());
}
public void close() throws IOException {
fd.close();
}
public void write(byte[] b) throws IOException {
fd.write(b);
}
public void write(byte[] b,int off,int len) throws IOException {
fd.write(b,off,len);
}
public void write(int b) throws IOException {
fd.write(b);
}
}
FileOutputStream fos = new FileOutputStream("myfile", true);
Written and compiled by Réal Gagnon ©1998-2005
[ home ]