1.java输出流缓存整体思路:
通过BufferedOutputStream将写入字节缓存到字节数组中,当超过缓存数组大小时,执行写入。
2.示例
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class BufferedOutputStreamTest {
public static void main(String[] args) throws IOException{
String filePath = "E:/1.txt";
File filePathObj = new File(filePath);
filePathObj.createNewFile();
FileOutputStream fileOut = new FileOutputStream(filePathObj);
BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOut);
try {
bufferedOutput.write("xxxx\r\n".getBytes());
} catch (IOException ignore) {
}
bufferedOutput.flush();
try {
bufferedOutput.write("yyy\r\n".getBytes());
} catch (IOException ignore) {
}
bufferedOutput.close();
}
}