java I/O系统总结
发布日期:2022-03-15 04:11:20 浏览次数:55 分类:技术文章

本文共 1291 字,大约阅读时间需要 4 分钟。

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、 带缓存的输入输出流

 

 

         

转载于:https://www.cnblogs.com/NeilZhang/p/6829717.html

转载地址:https://blog.csdn.net/weixin_30536513/article/details/99804930 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:程序员选择字体的标准是
下一篇:2019春第二次课程设计实验报告

发表评论

最新留言

很好
[***.229.124.182]2024年03月27日 11时37分45秒