zoukankan      html  css  js  c++  java
  • FileInputStream FileOutputStream

    FileInputStream is a stream to grab the information from files.Combined with FileOutputStream, we can achieve the function of copying.

    Examples:

    public class Demo4 {
     
     public static void main(String[] args) {
      String content = null;
      byte[] buffer = new byte[1024];
      int size = 0;
      File file = new File("C:/Users/caich5/Desktop/aaaa.txt");
      InputStream input = null;
      try {
          input = new FileInputStream(file);
          OutputStream output = new FileOutputStream("C:/Users/caich5/Desktop/tttd.txt");
       while((size = input.read(buffer))!= -1){
        //show in console
        content = new String(buffer,0,size);
        System.out.println(content);
        //copy to another file
        output.write(buffer, 0, size);
       }
       input.close();
      } catch (Exception e) {
       e.printStackTrace();
      }
     }
    }

    Tips: FileInputStream,FileOutputStream,both of them are low lever stream.

    Aimer,c'est partager
  • 相关阅读:
    选择排序
    插入排序
    洗牌算法
    访问性模式
    策略模式
    mysql EXPLAIN Join Types 手册解释 及数据实操
    Nginx Location和Rewrite总结
    json_decode 解析带BOM头文件错误
    laravel 集成 swagger插件
    php S3
  • 原文地址:https://www.cnblogs.com/pickKnow/p/8512493.html
Copyright © 2011-2022 走看看