I/O中的核心类:
一、字节流
InputStream ---抽象类
FileInputStream
OutputStream ---抽象类
FileOutputstream
InputStream:
int read(byte[] b, int off, int len)
返回值是实际读入的字节数
off是偏移量,len是最多读入的字节数
构造器中参数使用文件的全路径
OutputStream:
void write(byte[] b, int off, int len)
使用
import java.io.*导入类库
二、字符流:
Reader ---抽象类
FileReader
Writer ---抽象类
FileReader
Reader:
int read(char[] c, int off, int len)
Writer:
void write(char[] c, int off, int len)
三、节点流:被装饰者
处理流:装饰者
BufferedReader:
public String readLine() throws IOException
每次读取一行数据
BufferedReader in = new BufferedReader(new FileReader(“in.txt”));