1.数据库中使用BLOB字段
2.实体类中字段使用 byte[] 类型
3.将文件转成 byte[] 进行存取
/**
* 将文件转换成byte数组
*/
public static byte[] File2byte(File tradeFile){
byte[] buffer = null;
try
{
FileInputStream fis = new FileInputStream(tradeFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
return buffer;
}
Oracle数据库表中用字段存放文件
于 2024-04-02 13:45:58 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)