Java中的IO流(BufferedOutputStream)

BufferedOutputStream:

字节缓冲输入流
该类实现缓冲的输出流。通过设置这种输出流,应用程序就可以将各个字节写入底层输出流中
而不必针对每次字节写入调用底层系统。
父类:FilterOutputStream
从以下版本开始: JDK 1.0
操作系统不同,换行符不一样
(2)Windows系统里面,每行结尾是 回车+换行(CR+LF),即“\r\n”
(3)Unix系统里,每行结尾只有 换行LF,即“\n”;
(4)Mac系统里,每行结尾是 回车CR 即’\r’。

public static void main(String[] args) throws IOException {
		
		//1:创建字节缓冲输出流  包装流 (底层包装的是字节输出流   称之为节点流)
		BufferedOutputStream bos = new BufferedOutputStream(new 
		FileOutputStream("c.txt"));
		//2:往文件写数据
		//2.1 一次写一个字节
	
		//2.2 一次写一个字节数组
		bos.write(new byte[]{97,98,99,100,101});
		
	bos.write("\r\n".getBytes());
	
	bos.write(new byte[]{97,98,99,100,101});
	
	
	//3:关闭流  只需关闭高层流即可
	bos.close();
	bos.write(65);
	
	
	
}

猜你喜欢

转载自blog.csdn.net/qq_44013790/article/details/85330169