日期:2014-05-20 浏览次数:20775 次
File file = new File("image/temp.jpg");
if(file.exists()){
file.delete();
file.createNewFile();
}else{
file.createNewFile();
}
InputStream in = rs.getBinaryStream(5); //rs是连接数据库返回的ResultSet对象
FileOutputStream out = new FileOutputStream("image/temp.jpg");
byte[] bytes = new byte[1024];
int n;//将读取的文件写入到out流中
while ((n = in.read(bytes)) != -1) {
out.write(bytes, 0, n);
}
in.close();
out.close();
ImageIcon icon = new ImageIcon("image/temp.jpg");
JFrame frame = new JFrame(); JPanel panel = new JPanel();
frame.getContentPane().add(panel);
frame.getContentPane().setLayout(null); panel.setSize(400,400);
frame.setSize(400,400); panel.add(new JLabel(icon));
frame.setVisible(true);