您好,我正在使用下面的代码使用 java 从 postgresql bytea 检索文件,
但在文件中我得到了类似 314530413142313141 的数字
File file = new File("c:/test.doc");
FileOutputStream fos = new FileOutputStream(file);
ResultSet rs = st.executeQuery("SELECT * FROM test_bytea where id=" + 1);
if (rs != null) {
while (rs.next()) {
byte[] fileBytes = new byte[1024];
InputStream is = rs.getBinaryStream("type_file");
while (is.read(fileBytes) > 0) {
fos.write(fileBytes);
}
// use the stream in some way here
}
rs.close();
}
请让我知道我的代码出了什么问题?
数据被转义(以 \x 开头,然后是每个字节两个字符的十六进制),这是从 bytea 字段中出来的。在将其存储到文件中之前,您需要取消转义它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)