package com.dss.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* 使用缓冲区处理
*/
public class FisHuanchongTest {
public static void main(String[] args) {
//1.file源文件
File file = new File("d:"+File.separator+"ss.jpeg");
//2.创建字节流对象
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
//3.使用缓冲区
byte[] b = new byte[1024*2]; //缓冲区大小
int len = fis.read(b); //len:数组中的有效长度
/**
* 使用byte[]数组读取的时候,由于是数组,所以不存在byte为-1的情况
*/
while(len != -1){
len = fis.read(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(fis != null){
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
05-14
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-15
1380
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-23
2348
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交