//这个方法只是示例,不推荐这样使用
public static byte[] getFileByte(File file) throws Exception {
byte[] data = null;
InputStream in = new FileInputStream(file);
data = new byte[in.available()];
in.read(data);
in.close();
return data;
byte[] 转为 SerialBlob
Blob blob=new SerialBlob(readStream(str))
Blob转File
可以通过Blob转成InputStream,再通过读取的方式转成File
Blob转InputStream
InputStream in = blob.getBinaryStream()
InputStream转File
public void blobToFile(Blob blob,File file) throws Exception {
InputStream inStream=null;
OutputStream outStream=null;
try {
outStream = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[2048];
while ((bytesRead = inStream.read(buffer, 0, 2048)) != -1) {
outStream.write(buffer, 0, bytesRead);
}catch (Exception e){
throw new Exception(e);
}finally {
if(outStream!=null){
outStream.close();
if(inStream!=null){
inStream.close();