java 追加到文件尾
/**
*
* @param content要存储的内容
* @param fileName
*/
public static void append(String content,String fileName)
{
RandomAccessFile randomFile = null;
try
{
File file = new File(fileName);
if (!file.getParentFile().exists())
{
file.getParentFile().mkdirs();
}
randomFile = new RandomAccessFile(fileName, "rw");
// 文件长度,字节数
long fileLength = randomFile.length();
// 将写文件指针移到文件尾。
randomFile.seek(fileLength);
randomFile.write(content.getBytes());
randomFile.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}