简体   繁体   中英

byte array to image file in java

在此处输入图片说明

attached is an image file which i convert to byte array and writes back the byte array to a image file . it works fine . the value of the converted byte array is [B@5bc79255.

same file is attached ina n incident in HP service manager. and am using java wo connect trhough web service and download the attachment file as byte array and write to a image file . in this situation i face problem. this byte array which i retrieve from HPSM through the webservice function provided by them is [B@6e0e048a

as you can see values are also different. but surprisingly when i write [B@6e0e048a in to a image file , the size of the file is sero and nothing is there inside the file !!! where as if i convert the same file as byte array and writes back in to some image file its reproduced correctly!!

if you are using servlet to retrieve the bytes and if the image is base64 image, use :

while ((line = request.getReader().readLine()) != null)
                stringBuffer.append(line);

String base64Image = imageData.toString().split(",")[1];
            byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image);
            ByteArrayInputStream finalStream = new ByteArrayInputStream(stringBuffer);

and write finalStream to file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM