IO
1.概述
2.分类
自己的打开 能读懂的字符流,读不懂得字节流
3.字节流写数据(字节输出流)
public class OutputDemo {
public static void main(String[] args) throws IOException {
//1.创建字节输出流的对象
FileOutputStream fos=new FileOutputStream("D:\\wangzhuo.txt");
//2.写数据
fos.write(97);
//3。释放资源
fos.close();
}
}
字节流一次写多个数据
public class OutputDemo1 {
public static void main(String[] args) throws IOException {
//1.创建字节输出流的对象
FileOutputStream fos=new FileOutputStream("D:\\wangzhuo.txt");
//2.写数据
/* byte[] bytes={97,98,99,100};
fos.write(bytes);*/
byte[] bytes1={97,98,99,100,101,102,103};
fos.write(bytes1,1,6);
//3。释放资源
fos.close();
}
}
字节流2个问题:换行 续写
try catch finally
try catch finally 标准格式代码
4.字节流读数据(字节输入流)
public class InputDemo {
public static void main(String[] args) throws IOException {
//1.创建字节输出流的对象
FileInputStream fis=new FileInputStream("D:\\wangzhuo.txt");
//2.读数据
int read = fis.read();
System.out.println(read);
//3。释放资源
fis.close();
}
}
字节流读数据 一次读取多个数据
======= 1数据源 2目的地概念======
- 把文件内容读取出来 数据源
- 写入一个文件中 目的地
复制文件的代码 ↓
定义数组拷贝文件 ↓
4 缓冲流
缓冲流 一次读写一个字节
缓冲流 一次读写一个数组
字符流
编码
解码
字符流读取中文的过程
字符流 写数据 字符输出流
写数据的注意事项:
字符流 读数据 字符输入流
1 一次读取一个字符
2 一次读取都个字符
练习
字符缓冲流
字符缓冲输入流
字符缓冲输入流 读数据
字符缓冲输出流
字符缓冲输出流 写数据
转换流
对象操作流
Properties