向文件尾部追加内容

  //向文件尾部追加内容


public static void main( String [] args) throws FileNotFoundException,IOException { for (int i=0;i<100;i++){ appendContent("D:\\Q\\test\\testfile\\1.txt","这是第"+i); } } private static void appendContent(String filePath,String content) throws FileNotFoundException,IOException { RandomAccessFile randomAccessFile=new RandomAccessFile(filePath,"rw"); randomAccessFile.seek(randomAccessFile.length()); randomAccessFile.writeUTF(content+"\r\n"); randomAccessFile.close(); }

 

posted @ 2021-08-09 15:31  甜菜波波  阅读(88)  评论(0编辑  收藏  举报