public void saveToFile(Blob blob) {
try {
File file = new File("c:/someFileName.ext");
FileOutputStream os = new FileOutputStream(file);
os.write(getBlobBytes(blob));
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Error!");
}
}
public byte[] getBlobBytes(Blob blob) throws Exception {
final int MAXBUFSIZE = 4096;
if (blob != null) {
try {
BufferedInputStream bis = new BufferedInputStream(blob
.getBinaryStream());
ByteArrayOutputStream bo = new ByteArrayOutputStream();
byte[] buf = new byte[MAXBUFSIZE];
int n = 0;
while ((n = bis.read(buf, 0, MAXBUFSIZE)) != -1) {
bo.write(buf, 0, n);
}
bo.flush();
bo.close();
bis.close();
buf = null;
return bo.toByteArray();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return null;
}
No comments:
Post a Comment