1.继承自类InputStream,输入输出为字节流
2.FileInputStream 和FileOutputStream适用于操作于任何形式的文件(因为是以字节为向导),如果想要操作文本文件,采用FileInputReader和FileOutputWriter效率更高。
常用函数:
常用构造函数:
new FileInputStream(File XX)
new FileInputStream("a.txt")
读写函数(返回值为读的字节数,如果为-1则表示读完成):
read()-----一个字节--write()
read(Bytes[])--字节数组--read(Bytes[])
read(Bytes[],int start,int end)--指定起始字节数组--write(Bytes[],int start,int end)
关闭函数:
close
示例:
//如果该文件不存在,则直接创建,如果存在,删除后创建
FileOutputStream out = new FileOutputStream("demo/out.dat");out.write('A');//写出了'A'的低八位
out.write('B');//写出了'B'的低八位
int a = 10;//write只能写八位,那么写一个int需要写4次,每次8位
out.write(a >>> 24);
out.write(a >>> 16);
out.write(a >>> 8);
out.write(a);
byte[] gbk = "中国".getBytes("gbk");
out.write(gbk);
out.close();