多次向文件结尾写入数据

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="\r\n外星的小EZ你好啊".getBytes();
			raf.write(b);                  
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(raf!=null){
				raf.close();
			}
		}
	}

}

 

posted @ 2015-08-05 09:45  微软小菜鸟  阅读(410)  评论(0编辑  收藏  举报