public void read(){
String imagePath = "d:/lxp.bmp";
byte[] tmp = new byte[4096];
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
InputStream in = null;
try {
in = new FileInputStream(imagePath);
int len;
while((len = in.read(tmp)) != -1){
buffer.write(tmp,0,len);
}
imageData = buffer.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(in != null)
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
从本地读取图片保存为byte[]
最新推荐文章于 2024-08-03 08:40:05 发布
本文提供了一个使用Java代码从本地文件系统读取图片的方法。该示例展示了如何通过FileInputStream打开文件,逐块读取文件内容,并将其转换为字节数组存储。此外,还介绍了异常处理和资源关闭的最佳实践。
8965

被折叠的 条评论
为什么被折叠?



