⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagedb.java

📁 Enjoy Web Dev With Tapestry 一书的源代码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -