bufferedinputStream操作

  1. import java.io.BufferedInputStream;  
  2. import java.io.File;  
  3. import java.io.FileInputStream;  
  4. import java.io.FileNotFoundException;  
  5. import java.io.IOException;  
  6.   
  7.   
  8. public class BufferedInputStreamTest {  
  9.   
  10.     public static void main(String[] args) throws IOException {  
  11.         File file = new File("c:\\mm.txt");  
  12.         FileInputStream fis = new FileInputStream(file);  
  13.         BufferedInputStream bis = new BufferedInputStream(fis);  
  14.           
  15.         byte[] contents = new byte[1024];  
  16.         int byteRead = 0;  
  17.         String strFileContents;  
  18.           
  19.         try {  
  20.             while((byteRead = bis.read(contents)) != -1){  
  21.                 strFileContents = new String(contents,0,byteRead);  
  22.                 System.out.println(strFileContents);  
  23.             }  
  24.         } catch (IOException e) {  
  25.             // TODO Auto-generated catch block  
  26.             e.printStackTrace();  
  27.         }  
  28.         bis.close();  
  29.     }  
  30.   
  31. }  

 
  1. import java.io.BufferedInputStream;  
  2. import java.io.File;  
  3. import java.io.FileInputStream;  
  4. import java.io.FileNotFoundException;  
  5. import java.io.IOException;  
  6.   
  7.   
  8. public class ReadFileTest {  
  9.   
  10.     public static void main(String[] args) throws IOException {  
  11.         File file = new File("c:\\mm.txt");  
  12.         FileInputStream fis = new FileInputStream(file);  
  13.         BufferedInputStream bis = new BufferedInputStream(fis);  
  14.           
  15.         while(bis.available() > 0){  
  16.             System.out.print((char)bis.read());  
  17.         }  
  18.         bis.close();  
  19.     }  
  20.   
  21. }  
  1. import java.io.BufferedInputStream;  
  2. import java.io.BufferedOutputStream;  
  3. import java.io.FileInputStream;  
  4. import java.io.FileNotFoundException;  
  5. import java.io.FileOutputStream;  
  6. import java.io.IOException;  
  7. import java.io.InputStream;  
  8.   
  9.   
  10. public class BufferedInputStreamCopyFile {  
  11.   
  12.     public static void main(String[] args) throws IOException {  
  13.         BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:\\电影\\sn.ts"));  
  14.         BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("d:\\电影sn1.ts"));  
  15.           
  16.         int i;  
  17.           
  18.         do{  
  19.             i = bis.read();  
  20.             if(i != -1){  
  21.                 bos.write(i);  
  22.             }  
  23.         }while(i != -1);  
  24.   
  25.         bis.close();  
  26.         bos.close();  
  27.           
  28.           
  29.   
  30.     }  
  31.   
  32. }  
原文地址:https://www.cnblogs.com/fuccc/p/5698705.html