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
  • 相关阅读:
    newman
    集合自动化
    56. Merge Intervals
    55. Jump Game
    48. Rotate Image
    34. Search for a Range
    33. Search in Rotated Sorted Array
    16. 3Sum Closest
    15. 3Sum
    11. Container With Most Water
  • 原文地址:https://www.cnblogs.com/pickKnow/p/8512493.html
Copyright © 2011-2022 走看看