IO流
按照方向分可以分为输入流和输出流
按照文件的大小可以分为字符流和字节流
IO流有4大基类
InputStream OutputStream Reader Writer
输入流一般都包含input reader
输出流一般都包含output writer
1.一个字节一个字节读取
@Test
public void FirstIo01() throws Exception {
InputStream in = new FileInputStream("D:\\个人文件夹\\yang.txt");
int len = 0;
while ((len = in.read()) != -1) {
char c = (char) len;
System.out.print(c);
}
in.close();
}
2.用缓冲区进行读取
@Test
public void ThiredI002() throws Exception {
InputStream in = new FileInputStream("D:\\博客\\面向对象.docx");
byte[] b = new byte[8192];
int len = 0;
while ((len = in.read(b)) != -1) {
String str = new String(b, 0, len);
System.out.print(str);
}
in.close();
}