一、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.
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.
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.
Returns the name of the file or directory denoted by this abstract pathname.
Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
Converts this abstract pathname into a pathname string.
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