📄 imagedb.java
字号:
package com.ttdev.updown;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class ImageDB {
public static byte[] loadImage(int imageId) {
InputStream input = ImageDB.class.getResourceAsStream("/test.jpg");
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte buf[] = new byte[1024];
for (;;) {
try {
int noBytesRead = input.read(buf);
if (noBytesRead == -1) {
return output.toByteArray();
}
output.write(buf, 0, noBytesRead);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public static void saveImage(int imageId, byte[] imageData,
String imageFolder) {
File imageFile = new File(imageFolder, imageId + ".jpg");
try {
FileOutputStream output = new FileOutputStream(imageFile);
try {
output.write(imageData);
} finally {
output.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -