源码
package com.io;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class BufferedOutputStreamTest {
public static void main(String[] args) {
String path = "D:" + File.separator + "bufferedoutputstream.txt";
BufferedOutputStreamWirteFile(path);
}
private static void BufferedOutputStreamWirteFile(String path) {
try (
OutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(path), true))) {
StringBuffer buf = new StringBuffer();
buf.append("Hello World!").append("\r\n");
buf.append("Hello Java!").append("\r\n");
buf.append("Hello Shao Yv!").append("\r\n");
buf.append("Hello Jing Tianming!").append("\r\n");
buf.append("Hello Gao Yue!").append("\r\n");
bos.write(buf.toString().getBytes());
bos.write(buf.toString().getBytes());
bos.write(buf.toString().getBytes());
bos.flush();
} catch (
Exception e) {
}
}
}