package javaBasic;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* BufferedInputStream(FileInputStream in)
* BufferedOutputStream(FileOutputStream out)
* 可以提高性能
* @author markGao
*
*/
public class BufferedStreamDemo {
public static void main(String[] args) throws IOException {
// BufferedInputStream普通写法
String file = "out.txt";
InputStream ins = new FileInputStream(file);
BufferedInputStream bufin = new BufferedInputStream(ins);
int b;
while ((b = bufin.read()) != -1) {
System.out.println(Integer.toHexString(b));
}
// 常用写法,只要用到FileInputStream的地方都可以套一个BufferedInputStream用来提升性能
@SuppressWarnings("unused")
BufferedInputStream in = new BufferedInputStream(new FileInputStream(
"out.txt"));
// BufferedOutputStream
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream("out.txt"));
out.write(65);
}
}
转载于:https://my.oschina.net/u/1412027/blog/220612