IO流
作用
程序与文件传输数据的通道
分类
按照流向分类:
输入流
输出流
按照最小传输单位分类:
字节流
字符流
按照功能分类
节点流
过滤流
字节流
父类:
InputStream (抽象类)
read()
read(byte[] b)
read(byte[] b , int off , int len)
close() 关闭流
OutputStream(抽象类)
write()
write(byte[] b)
write(byte[] b , int off ,int len)
flush()
close()
常用子类
文件流
作用:读取文件中的内容 或者 给文件中写入内容
FileInputStream
FileOutputStream
public static void main(String[] args) throws IOException {
FileInputStream fs = new FileInputStream("D:\\桌面\\Day06.txt");
FileOutputStream fo = new FileOutputStream("D:\\缓冲流.txt" , true);
BufferedInputStream bi = new BufferedInputStream(fs);
BufferedOutputStream bo = new BufferedOutputStream(fo);
byte[] b = new byte[1024];
int len = 0;
while ((len = bi.read()) != -1) {
bi.read(b, 0, len);
bo.write(b);
bo.flush();
}
bo.close();
bi.close();
System.out.println("缓冲流测试成功,出现乱码问题");
}
内存流
作用: 将数据读取到内存中 或者 从内存中取出数据
ByteArrayInputStream
ByteArrayOutputStream
public static void main(String[] args) throws IOException {
FileInputStream fi = new FileInputStream("D:\\桌面\\D