package com.ZAMPSDK.geo; import java.io.File; import java.io.FileOutputStream; import java.io.*; public class FileTest { public static void writeIPInfo(String line) { FileOutputStream outSTr = null; BufferedOutputStream Buff = null; try { outSTr = new FileOutputStream(new File("D:\\working\\test.txt")); Buff = new BufferedOutputStream(outSTr); long begin0 = System.currentTimeMillis(); Buff.write((line + "\n").getBytes()); Buff.flush(); Buff.close(); long end0 = System.currentTimeMillis(); System.out.println("BufferedOutputStream执行耗时: " + (end0 - begin0) + " 豪秒 "); } catch (Exception e) { e.printStackTrace(); } finally { try { Buff.close(); outSTr.close(); } catch (Exception e) { e.printStackTrace(); } } } public static void appendMethodB( String content) { try { //打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件 FileWriter writer = new FileWriter("D:\\working\\test.txt", true); writer.write(content+"\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { for (int i = 0; i < 8; i++) { appendMethodB("=======" + i); } } }
java io 写文件,包括追加写文件
最新推荐文章于 2021-09-23 22:17:24 发布