0
点赞
收藏
分享

微信扫一扫

向文件中追加内容

芝婵 2022-03-11 阅读 83
java
    /*
     *actions: 向文件中追加内容
	 *fileName:文件路径
	 *content:内容
	 */
	public static void method3(String fileName, String content) {
		try {
            // 打开一个随机访问文件流,按读写方式
			RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
            // 文件长度,字节数
			long fileLength = randomFile.length();
            // 将写文件指针移到文件尾。
			randomFile.seek(fileLength);
			randomFile.writeBytes(content+"\r\n");
			randomFile.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
举报

相关推荐

0 条评论