Java 使用JDBC从配置单元获取图像数据(存储为二进制)
我从一个存储为二进制数据的蜂巢中获取图像数据,如 通过使用Java 使用JDBC从配置单元获取图像数据(存储为二进制),java,hadoop,jdbc,hive,Java,Hadoop,Jdbc,Hive,我从一个存储为二进制数据的蜂巢中获取图像数据,如 通过使用InputStream对象。问题是,当我试图对图像进行编码时,它被编码了,但当我试图对同一编码图像进行解码时,它又抛出了一个错误 我的程序如下所示: File file=new File("path"); java.io.InputStream in = rs1.getBinaryStream("entity_image"); OutputStream f = new FileOutputStrea
InputStream
对象。问题是,当我试图对图像进行编码时,它被编码了,但当我试图对同一编码图像进行解码时,它又抛出了一个错误
我的程序如下所示:
File file=new File("path");
java.io.InputStream in = rs1.getBinaryStream("entity_image");
OutputStream f = new FileOutputStream(file);
int c=0;
while((c=in.read())>-1)
{
//System.out.println(c);
f.write(c);
}
byte[] imageBytes = new byte[(int)file.length()];
in.read(imageBytes, 0, imageBytes.length);
in.close();
String imageStr = encodeImage(imageBytes);//method that returns the encoded base64 String.
byte[] imageByteArray = decodeImage(imgstring);//method returning byte []
f.write(imageByteArray);//writing the decoded image to the file
getbytes()
方法进行了检查,但它表示不支持该方法请显示您看到的stacktrace/错误我在运行程序时没有收到错误,但在操作图像时收到错误,如:错误解释JPEG图像文件(不是JPEG文件:以0x00 0x00开始,但最终我得到了解决方案,谢谢