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); } }