Java学习7--FileInputStream,FileOutputSteam类

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();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值