zoukankan      html  css  js  c++  java
  • java I/O系统总结

    1、 InputStream : 从文件、网络、压缩包等中读取 需要的信息到程序中的变量

        read();     read(byte []b );

        mark(int readlimit);

        reset();  将输入指针返回到当前所做的标记处

        skip(long n);  close();

    子类:  FileInputStream

        FilterInputStream——BufferInputStream,DataInputStream.....(FIleInputStream的子类)

        StringBufferInputStream

    2、 OutputStream :  将内存中的信息 输出到 文件、网络、压缩包中

        write(int n); //指定的字节写入到输出流

        write(byte[] b) ; write(byte[]b,int off,int len);

        flush();  //彻底完成输出,并清空缓冲区

        close();

    3、 File 类

      构造方法:  File(String PathName);  //可以是一个路径,也可以是一个路径+文件 

            File(String fater,String child);

            File(File f,String child);

      成员:    createNewFile();

            .delete(); .getName(); .canRead();canWrtie();exists();length();

           .getAbsolutePath(); isFile(); isDirectory();......

    4、文件输入输出流

    FileInputStream、FileOutputStream 以字节流的形式输入输出

      new FileInputStream(File f);

      new FileInputStream(String name); // 通过给定的文件名创建FileInputStram对象

      read(byte []b) ; 将FIle中的信息读取到 byte数组中

      同样:FIleOutStream();
      write(byte []b); 将信息写入到文件中

      byte[] b = "hello world".getBytes(gbk); //得到
      如果不指定编码格式,得到系统自带的编码格式。可以指定: gbk utf-8 iso-8859-1
      String s_gbk = new String(b, "gbk"); // 与上述过程相反

     FileReader 和 FileWriter (以字符流的形式输出)

       .read(char []c);  .write(String s);  

    5、 带缓存的输入输出流

             

  • 相关阅读:
    D. Babaei and Birthday Cake--- Codeforces Round #343 (Div. 2)
    Vijos P1389婚礼上的小杉
    AIM Tech Round (Div. 2) C. Graph and String
    HDU 5627Clarke and MST
    bzoj 3332 旧试题
    codeforces 842C Ilya And The Tree
    codesforces 671D Roads in Yusland
    Travelling
    codeforces 606C Sorting Railway Cars
    codeforces 651C Watchmen
  • 原文地址:https://www.cnblogs.com/NeilZhang/p/6829717.html
Copyright © 2011-2022 走看看