1:IO流的分类:按照流的方向来分,可以分为输入流和输出流。
按照流动的数据类型来分,可以分为:字节流和字符流
字符流: 字符流:
输入流:InputStream 输入流:Reader
输出流:OutputStream 输出流:Writer
一切皆字节:计算机中的任何数据都是以二进制存储,在数据传输时是以二进制存储
1:OutStream:
FileOutStream fos = new FileOutputStream("c://a.txt",true) // true 为追加,Out为写进文件中
byte[] b = new byte[]{66,77,88};
fos.write(b);
byte[] b = "abcd".getBytes();//getBytes 方法把字符串变成字节数组
for.write(bytes,1,2);//以1下标开始写,写两个内容,并不是写1下标和2下标
2:InputStream
FileInputStream fis = new FileInputStream("c://a.txt");
byte[] bytes = new byte[100];
int b =( byte) fis.read();//获取最大长度,保证不会输出空
System.out.println(new String(bytes,o,b));
3. Reader
FileReader fr = new FileReader("b://a.txt");
char[] chars = new char[100];
int len = fr.read(chars);
String text = new String (Chars ,0,len);
System.out.println(text);
fr.close;