1.说明流的三种分类方式
2.写出4个IO流中的抽象基类,4个文件流,4个缓冲流
3.字节流与字符流的区别与使用情境
4.使用缓冲流实现a.jpg文件复制为b.jpg文件的操作
5.转换流是哪两个类,分别的作用是什么?请分别创建两个类的对象。
按流的数据单位分:字节流、字符流
按流向分:输入流、输出流
按流角色:节点流、处理流
Reader Writer InputStream OutputStream
FileReader FileWriter FileInputStream FileOutputStream
BufferedReader BufferedWriter BufferedInputStream BufferedOutputStream
字节流的数据是以字节为单位进行传输,非文本文件
字符流的数据是以字符为单位进行传输,文本文件
public class Demo1 {
public static void main(String[] args) {
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
fileInputStream = new FileInputStream("123.jpg");
fileOutputStream = new FileOutputStream("jqk.jpg");
bis = new BufferedInputStream(fileInputStream);
bos = new BufferedOutputStream(fileOutputStream);
byte[] bytes = new byte[10];
int len;
while ((len = bis.read(bytes)) != -1) {
bos.write(bytes, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
InputStreamReader:将输入的字节流转换为字符流。解码,构造器里面可以指定编码类型,也可以默认,要与源文件一致
OutputStreamWriter:将输出的字符流转换为字节流。编码,构造器里面可以指定编码类型,也可以默认