向文件末尾追加内容

import java.io.*;
public class AppendContent
{
    public static void main(String[] args)
    {
        try(RandomAccessFile raf = new RandomAccessFile("out2.txt", "rw"))
        {
            raf.seek(raf.length());
            raf.write("追加的内容! \r\n".getBytes());
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }
}

将看到out2.txt文件中:追加的内容! 

转载于:https://www.cnblogs.com/bailun/archive/2013/05/29/3106548.html

你可能感兴趣的:(向文件末尾追加内容)