java -- 讀取和輸出圖片到本地
阿新 • • 發佈:2019-02-03
public static byte[] getLocalPicture() throws Exception {
byte[] data = null;
FileImageInputStream input = new FileImageInputStream(new File(
"d://HaierVR.jpg"));
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int numBytesRead = 0;
while ((numBytesRead = input.read(buf)) != -1) {
output.write(buf, 0, numBytesRead);
}
data = output.toByteArray();
output.close();
input.close();
return data;
}
public static void writeLocalPicture(byte[] data) throws Exception {
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(
"e://123.jpg"));
imageOutput.write(data, 0, data.length);
imageOutput.close();
}