在java中,要对各类型文件或设备进行访问,或者向文件、设备中写入数据,那么一定会用到I/O流。
1.java流类的分类
字节流 字符流
输入流: inputStream reader
输出流: outputStream writer
java中的基础流可以分为以上4类。以上4类都拥有类似的方法:
inputStream类或outputStream类共有方法
int read throws IOException
int read(btye[] buffer) throws IOException
int read(btye[] buffer ,int offset , int length ) throws IOException
void close() throws IOException
reader类或writer类共有方法
void writer throws IOException
void writer(btye[] buffer) throws IOException
void writer(btye[] buffer ,int offset , int length ) throws IOException
void close() throws IOException
void flush() throws IOException //刷新缓冲区(流管道)用的。
2.节点流和处理流
节点流类型
字符流 字节流
File(文件) FileReader FileInputStream
FileWriter FileOutputStream
Memory Array CharArrayReader ByteArrayInputStream
CharArrayWriter ByteArrayOutputStream
Memory String StringReader
StringWriter
Piped(管道) PipedReader PipedInputStream
PipedWriter PipedOutputStream
4.文件流
File(文件) FileReader FileInputStream
FileWriter FileOutputStream
5.缓冲流
BufferFileReader(Reader in)
BufferFileReader(Reader in , int sz) //sz为自定义缓冲区大小
BufferFileWriter(Writer out)
BufferFileWriter(Writer out , int sz)
BufferFileInputStream(InputStream in)
BufferFileInputStream(InputStream in , int sz )
BufferFileOutputStream(OutputStream out )
BufferFileOutputStream(OutputStream out , int sz )
BufferFileReader(Reader in)提供了readLine用于读取一行字符串。
BufferFileWriter(Writer out)提供了newLine用于输出一行字符串。
6.数据流
DataInputStream和DataOutputStream都属于处理流,分别嵌套在InputStream或OutputStream类型的节点流上。
7.转换流
8.print流
9.object流