imagedb.java
来自「Enjoy Web Dev With Tapestry 一书的源代码」· Java 代码 · 共 37 行
JAVA
37 行
package com.ttdev.album;
import java.io.*;
public class ImageDB {
public static byte[] loadImage(int imageId, String imageFolder) {
try {
FileInputStream input = new FileInputStream(new File(imageFolder, imageId + ".jpg"));
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte buf[] = new byte[1024];
for (;;) {
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 + =
减小字号Ctrl + -
显示快捷键?