多次向文件结尾写入数据

package shi;

import java.io.*;

public class suiji {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		RandomAccessFile raf=null;
		File f=new File("F:/test/123.txt");
		try {
			raf=new RandomAccessFile(f,"rw");
//			seek跳过文件本身的长度,向结尾处写入
			raf.seek(f.length());			
			byte[]b="
外星的小EZ你好啊".getBytes();
			raf.write(b);                  
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(raf!=null){
				raf.close();
			}
		}
	}

}
原文地址:https://www.cnblogs.com/xiaoqisfzh/p/4703878.html