package cn.itcast_05;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;/* * 注意:雖然我們有兩種方式可以讀取,但是,請注意,這兩種方式針對同一個對象在一個代碼中只能使用一個。 */public class BufferedInputStreamDemo { public static void main(String[] args) throws IOException { // BufferedInputStream(InputStream in) BufferedInputStream bis = new BufferedInputStream(new FileInputStream( "bos.txt")); // // 讀取數(shù)據(jù) // int len = 0; // while ((len = bis.read()) != -1) { // System.out.PRint((char) len); // } // System.out.println("----------------"); byte[] bys = new byte[1024]; int len = 0; while ((len = bis.read(bys)) != -1) { System.out.println(new String(bys, 0, len)); } // 釋放資源 bis.close(); }}
|
新聞熱點
疑難解答