一、输入/输出流 (java.io包)
1. 输入流
输入流类都是抽象类InputStream(字节输入流)或Reader(字符输入流)的子类。
(1) InputStream类 (该类所有方法抛出的异常都会引发IOException异常)
常用方法:read()
read(byte[] b)
close()
(2) Reader类
该类在处理字符文本时较方便。
2. 输出流
输出流类都是抽象类OutputStream(字节输出流)或Writer(字符输出流)的子类。
(1) OutputStream类
常用方法:write(byte b)
write(byte[] b)
write(byte[] b,int off,int len)
close()
(2) Writer类
二、File类
1. 文件创建:
new file(String pathname); ///路径中包含文件名
new file(String parent, String child);
new file(File f,String child);
2. 获取文件信息
getName()
canRead()/canWrite()
exits()
length() ///按字节计算
getAbsolutePath()/getParent()
isFile()/isDirectory()/isHidden()
lastModified()
3. 文件输入输出流
(1) FileInputStream 与 FileOutputStream
构造函数:FileInputStream(String name) 和FileInputStream(File file)
FileOutputStream构造函数同上(可以指定一个不存在的文件名,但不能指定一个已被其他程序打开的文件)
(2) FileReader 与 FileWriter (字符流)
三、带缓存的输入/输出流
带缓存的输入输出不是直接直接对流写入写出,而是和缓存对接,当缓存区满时,才写入写出。
(1) BufferedInputStream 与 BufferedOutputStream
构造函数:BufferedInputStream(InputStream in,int size); ///当参数没有size时,默认缓存流是32字节
BufferedOutputStream 同上
特有方法:flush() //强制即使缓存区没满,也将缓存区的数据写入写出。(当调用close()时,系统在关闭流之前,也会将缓存区中信息刷新)
(2) BufferedReader 与 BufferedWriter
特有方法:readLine()
四、数据输入/输出流 :允许应用程序以与机器无关的方式从底层输入流中读取基本java数据类型,而不必管这个数据占几个字节。
DataInputStream 与 DataOutputStream
构造函数:DataInputStream(InputStream in)
DataOutputStream(OutputStream out)
特有方法:writeBytes(String s)
writeChars(String s)
writeUTF(String s)
readUTF()
五、ZIP压缩输入/输出流
ZipOutputStream(OutputStream out);
ZipInputStream(InputStream in);
1. 输入流
输入流类都是抽象类InputStream(字节输入流)或Reader(字符输入流)的子类。
(1) InputStream类 (该类所有方法抛出的异常都会引发IOException异常)
常用方法:read()
read(byte[] b)
close()
(2) Reader类
该类在处理字符文本时较方便。
2. 输出流
输出流类都是抽象类OutputStream(字节输出流)或Writer(字符输出流)的子类。
(1) OutputStream类
常用方法:write(byte b)
write(byte[] b)
write(byte[] b,int off,int len)
close()
(2) Writer类
二、File类
1. 文件创建:
new file(String pathname); ///路径中包含文件名
new file(String parent, String child);
new file(File f,String child);
2. 获取文件信息
getName()
canRead()/canWrite()
exits()
length() ///按字节计算
getAbsolutePath()/getParent()
isFile()/isDirectory()/isHidden()
lastModified()
3. 文件输入输出流
(1) FileInputStream 与 FileOutputStream
构造函数:FileInputStream(String name) 和FileInputStream(File file)
FileOutputStream构造函数同上(可以指定一个不存在的文件名,但不能指定一个已被其他程序打开的文件)
(2) FileReader 与 FileWriter (字符流)
三、带缓存的输入/输出流
带缓存的输入输出不是直接直接对流写入写出,而是和缓存对接,当缓存区满时,才写入写出。
(1) BufferedInputStream 与 BufferedOutputStream
构造函数:BufferedInputStream(InputStream in,int size); ///当参数没有size时,默认缓存流是32字节
BufferedOutputStream 同上
特有方法:flush() //强制即使缓存区没满,也将缓存区的数据写入写出。(当调用close()时,系统在关闭流之前,也会将缓存区中信息刷新)
(2) BufferedReader 与 BufferedWriter
特有方法:readLine()
四、数据输入/输出流 :允许应用程序以与机器无关的方式从底层输入流中读取基本java数据类型,而不必管这个数据占几个字节。
DataInputStream 与 DataOutputStream
构造函数:DataInputStream(InputStream in)
DataOutputStream(OutputStream out)
特有方法:writeBytes(String s)
writeChars(String s)
writeUTF(String s)
readUTF()
五、ZIP压缩输入/输出流
ZipOutputStream(OutputStream out);
ZipInputStream(InputStream in);