首页 > 编程语言 > 详细

Java基础知识强化之IO流笔记27:FileInputStream读取数据一次一个字节数组byte[ ]

时间:2015-10-08 19:57:20      阅读:218      评论:0      收藏:0      [点我收藏+]

1. FileInputStream读取数据一次一个字节数组byte[ ]

 使用FileInputStream一次读取一个字节数组:

  int read(byte[]  b)

  返回值:返回值其实是实际读取的字节个数 .

 

2. 代码示例:

 1 package com.himi.fileinputstream;
 2 
 3 import java.io.FileInputStream;
 4 import java.io.IOException;
 5 
 6 
 7 
 8 /**
 9  * 
10  * 使用FileInputStream一次读取一个字节数组:int read(byte[] b)
11  * 返回值:返回值其实是实际读取的字节个数
12  * 
13  */
14 
15 
16 public class FileInputStreamDemo1 {
17 
18     public static void main(String[] args) throws IOException {
19         FileInputStream fis = new FileInputStream("a.txt");
20     //开发时候最终版本代码
21         byte[] bys = new byte[1024];
22         int len = 0;
23         while((len = fis.read(bys)) != -1) {
24             System.out.print(new String(bys,0,len));
25         }
26         
27     }
28 
29 }

运行效果,如下:

技术分享

Java基础知识强化之IO流笔记27:FileInputStream读取数据一次一个字节数组byte[ ]

原文:http://www.cnblogs.com/hebao0514/p/4861871.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!