Java字节流输入流FileInputStream的简单使用

官网API:

https://docs.oracle.com/javase/8/docs/api/java/io/FileInputStream.html

	public static void main(String[] args) throws IOException {
		getConstructor();
		//getLoanShift();
		//getLoanShiftThree();
	}
	/**
	 * read(byte[],int off,int len),和read(byte[] b)差不多
	 */
	private static void getLoanShiftThree() throws IOException {
		FileInputStream fis = new FileInputStream(new File("D:\\a.txt"));
		byte[] b = new byte[2];
		int len = 0;
		while((len = fis.read(b, 0, b.length)) != -1){
			System.out.print(new String( b, 0, len));
		}
		fis.close();
	}

	/**
	 * read(byte[] b)  返回读取到的字节数
	 * 如果byte数组字节数为2,文件内容为abcde,2个字节依次读取三次那么读取结果就abcded
	 * 		第一次:byte{a,b},第二次:byte{c,d},第三次:byte{e,d},覆盖式的写入,最后一个没有了所以d没有被覆盖写入遗留的,byte数组读取到的字节数为2,2,1
	 * 		使用String的构造方法来完成:String(要读取的数组,开始位置,结束位置);这样读取的就是2,2,1,字符是ab,cd,e
	 */
	private static void getLoanShift() throws IOException {
		FileInputStream fis = new FileInputStream(new
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值