日期:2014-05-20 浏览次数:20714 次
import java.io.*; public class TestBufferStream1 { public static void main(String args[]) { try { FileInputStream fis = new FileInputStream("c:/java/IO/TestFileInputStream.java"); BufferedInputStream bis = new BufferedInputStream(fis); int c = 0; System.out.println(bis.read()); System.out.println(bis.read()); bis.mark(100); for(int i = 0; i < 10 && ((c = bis.read()) != -1); i ++ ) { System.out.print((char)c + " "); } bis.reset(); System.out.println(); for(int i = 0; i < 10 && ((c = bis.read()) != -1); i ++ ) { System.out.print(c + " "); } bis.close(); //为什么fis不用关闭那!? } catch (IOException e) { e.printStackTrace(); } } }