62,614
社区成员
发帖
与我相关
我的任务
分享
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
File file = new File(path); //path为d:\tomcat\temptest.txt
FileInputStream fileinputstream = new FileInputStream(file);
byte[] chunk = new byte[blob.getChunkSize()];
int i = -1;
while ((i = fileinputstream.read(chunk)) != -1) {
outputstream.write(chunk, 0, i);
}
path是systemTemp + fileName来的
systemTemp = d:\tomcat\temp(temp后面没有"\")
fileName = test.txt
我上传附件的时候,d:\tomcat\temp下面并没有test.txt(而且用exist()判断返回的也是true不明白为什么)
而且上面代码在执行的时候不明白为什么test.txt的内容能被写到数据库里(如果是d:\tomcat\temp\test.txt被写进去可能明白)
哪位朋友能给讲一下吗谢谢
FileInputStream fileinputstream = new FileInputStream(file); // 文件输入流
byte[] chunk = new byte[blob.getChunkSize()]; // 设置读取缓冲区大小
int i = -1;
while ((i = fileinputstream.read(chunk)) != -1) { // 读取信息
outputstream.write(chunk, 0, i); // 写入blob里面
}