zoukankan      html  css  js  c++  java
  • 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. }  
  • 相关阅读:
    进程间通信 —— 命名管道
    判断当前线程是否有管理者权限
    获取操作系统OS等相关信息
    VS2017编译动态链接库报错
    git rebase 和 git merger
    Android开发之深入理解泛型extends和super的区别
    Android开发之深入理解Android Studio构建文件build.gradle配置
    Android开发之深入理解Android 7.0系统权限更改相关文档
    Android 开发之深入理解安卓调试桥各种错误解决办法
    自定义弹窗 VS AlertDialog分享弹窗
  • 原文地址:https://www.cnblogs.com/fuccc/p/5698705.html
Copyright © 2011-2022 走看看