Java I/O

作者: ChildeChan | 来源:发表于2018-01-25 22:20 被阅读0次

一、File类

File类不是指代文件或者文件目录,只是代表文件或者文件目录的名称。

构造方法

Constructor and Description

File(File parent, String child)

Creates a new File instance from a parent abstract pathname and a child pathname string.

File(String pathname)

Creates a new File instance by converting the given pathname string into an abstract pathname.

File(String parent, String child)

Creates a new File instance from a parent pathname string and a child pathname string.

File(URI uri)

Creates a new File instance by converting the given file: URI into an abstract pathname.

常用方法

boolean   createNewFile()

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist

boolean   delete()

Deletes the file or directory denoted by this abstract pathname.

boolean   exists()

Tests whether the file or directory denoted by this abstract pathname exists.

String    getName()

Returns the name of the file or directory denoted by this abstract pathname.

String    getParent()  

Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

File       getParentFile()

Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

String      getPath()

Converts this abstract pathname into a pathname string.

File[]       listFiles()

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

boolean   mkdir()

Creates the directory named by this abstract pathname.

boolean   mkdirs()

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.

二、输入和输出

所有的输入输出流都是字节流继承自 InputStream 和Outputsteam.

读和写操作都是字符流继承自Reader和Writer.

按照其功能分为如下图所示的各类:

一、按I/O类型来总体分类:

1. Memory1)从/向内存数组读写数据: CharArrayReader、 CharArrayWriter、ByteArrayInputStream、ByteArrayOutputStream2)从/向内存字符串读写数据 StringReader、StringWriter、StringBufferInputStream2.Pipe管道  实现管道的输入和输出(进程间通信): PipedReader、PipedWriter、PipedInputStream、PipedOutputStream3.File 文件流。对文件进行读、写操作 :FileReader、FileWriter、FileInputStream、FileOutputStream4. ObjectSerialization 对象输入、输出:ObjectInputStream、ObjectOutputStream5.DataConversion数据流按基本数据类型读、写(处理的数据是Java的基本类型(如布尔型,字节,整数和浮点数)):DataInputStream、DataOutputStream6.Printing包含方便的打印方法 :PrintWriter、PrintStream7.Buffering缓冲 在读入或写出时,对数据进行缓存,以减少I/O的次数:BufferedReader、BufferedWriter、BufferedInputStream、BufferedOutputStream8.Filtering 滤流,在数据进行读或写时进行过滤:FilterReader、FilterWriter、FilterInputStream、FilterOutputStream过9.Concatenation合并输入把多个输入流连接成一个输入流 :SequenceInputStream10.Counting计数在读入数据时对行记数 :LineNumberReader、LineNumberInputStream11.Peeking Ahead通过缓存机制,进行预读 :PushbackReader、PushbackInputStream12.Converting between Bytes and Characters按照一定的编码/解码标准将字节流转换为字符流,或进行反向转换(Stream到Reader,Writer的转换类):InputStreamReader、OutputStreamWriter

二、按数据来源(去向)分类:

1、File(文件): FileInputStream, FileOutputStream, FileReader, FileWriter

2、byte[]:ByteArrayInputStream, ByteArrayOutputStream

3、Char[]: CharArrayReader, CharArrayWriter

4、String: StringBufferInputStream, StringReader, StringWriter

5、网络数据流:InputStream, OutputStream, Reader, Writer

相关文章

  • 线上学习资料汇总_新

    1. Java I/O 这些年一直记不住的 Java I/O 深入分析 Java I/O 的工作机制 NIO 入门...

  • NIO.2-简介

    More New I/O Java 7 中的 More New I/O APIs,通过在 java.nio.cha...

  • Java & Groovy & Scala & Kotlin -

    Overview 文章介绍的 I/O 主要用于本地文件读写,不涉及网络 I/O。 Java 篇 Java 中的 I...

  • I/O

    Java I/O 总结 理解Java中字符流与字节流的区别 深入学习 Java 序列化 Java I/O 操作及优...

  • 知识总结:I/O模型基础

    I/O基础 1、java1.4之前,java对I/O支持不完善,存在以下问题: 没有数据缓冲区,I/O性能存在问题...

  • Netty 权威指南笔记(一):网络 I/O 模型和 Java

    Netty 权威指南笔记(一):网络 I/O 模型和 Java IO 入门 Java I/O 模型的实现离不开底层...

  • Java I/O

    Java I/O主要包括三个部分1.流式部分2.非流式部分3.其他类 1.字符流 字符流处理文本数据,在java中...

  • java I/O

    一.文件/文件夹File 二.InputStream/OutputStream字节输入输出流 三.关闭流的方式 四...

  • Java I/O

    如果当初陪着你的人走远了,那些日子回忆起来会模糊吗? mark 标记reset 重置exist 存在modifie...

  • Java I/O

    流可以理解为一个有顺序的,有起点和终点的数据序列,输入流表示从一个源读取数据,输出流表示向一个目标写数据。 字节流...

网友评论

      本文标题:Java I/O

      本文链接:https://www.haomeiwen.com/subject/vvzvaxtx.html