package cn.itast.chap.sttt01.IO_FileIoputStream输入流和FileOutputStream输出流;
import java.io.*;
/**
* int read (byte[] bytes);
* 读取之前在内存中准备一个byte数组,每次读取多个字节存储到byte数组中,
* 一次读取多少个字节,不是单字节读取了
* 效率高
*
*
* */
public class FileInputStream_Test02 {
public static void main(String[] args) throws Exception{
//创建输入流
FileInputStream fis = new FileInputStream("D:\\MnysLjj\\time.txt");
//开始读
//准备一个byte数组
byte[] bytes = new byte[3];//每一次读取三个
//int read(byte[] bytes);该方法返回的int类型的值代表的是,这次读取了多少个字节.,
int i1 ;
while((i1 = fis.read(bytes)) !=-1) {
System.out.print(new String(bytes, 0 ,bytes.length-1));
}
//关闭
fis.close();
}
}
FileInputStream_Test02
最新推荐文章于 2024-08-01 15:05:06 发布