- 图片的属性(字节长度),如图:
- 上代码:
package com.dss.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* 使用字节流读取图片操作
*/
public class FisImageTest {
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);
int len = fis.read();
int count = 0;
while(len != -1){
count++;
System.out.println(len);//读取字节
len = fis.read();
}
System.out.println("count字节数: " + count);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(fis != null){
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
67
71
255
217
count字节数: 173726
Disconnected from the target VM, address: '127.0.0.1:63061', transport: 'socket'
注意: 读取的字节数都是173726