标签:图片 read enter 内存 public lock txt static plain
一、IO流
I表示的是in,O表示的是Out,In代表输入,Out代表输出
IO流是内存和硬盘之间的数据交互
1.2、IO的分类

| 方法 | 说明 |
|---|---|
| close() | 关闭流资源 |
| write(byte[] b) | 把字节数组中的每个字节输出到文件中 |
| write(byte[] b, int off, int len) | 把字节数组中一部分字节输出到文件中 |
| write(int b) |
| 方法 | 说明 |
|---|---|
| public FileOutputStream(File file) | 向指定文件位置输出数据 |
| public FileOutputStream(String name) | 向指定字符串路径输出数据 |
| public FileOutputStream(File file,boolean b) | 创建对象的同时指定是否续写true表示是 |
| public FileOutputStream(String name,boolean b) |
IO流就是是水流,开启资源后,就要关闭
在不同的系统中换行符号不一样,window中是\r\n
| 方法 | 说明 |
|---|---|
| close() | 关闭流资源 |
| read() | 每次读取一个字节,返回值代表的是字节 |
| read(byte[] b) |
| 说明 | |
|---|---|
| FileInputStream(File file) | 从指定的File文件读取数据 |
| FileInputStream(String name) | 从指定字符串路径位置读取数据 |
public class Demo字节输入流 {
public static void main(String[] args) throws Exception {
//FileInputStream(File file)
//从指定的File文件读取数据
//FileInputStream fis = new FileInputStream(new File("day15\\aaa\\123.txt"));
//FileInputStream(String name)
//从指定字符串路径位置读取数据
//如果文件不存在,会直接报错:系统找不到指定的文件。
//在流里面不能写文件夹,会报错:拒绝访问。
FileInputStream fis = new FileInputStream("day15\\aaa\\123.txt");
}
}
读取用循环读取
案列:图片复制

标签:图片 read enter 内存 public lock txt static plain
原文地址:https://www.cnblogs.com/gushiye/p/13860952.html