Java Base64 image encoding and decoding

Source: Internet
Author: User
Tags base64

Image.base64.Base64ImageConvertor.java

Package image;import sun.misc.base64decoder;import sun.misc.base64encoder;import java.io.* ;p ublic class base64imageconvertor {    public static string  convertimagetostring (File file)  throws Exception {         base64encoder base64encoder = new base64encoder ();         fileinputstream fis = new fileinputstream (file);         ByteArrayOutputStream byteArrayOutputStream = new  Bytearrayoutputstream ();         base64encoder.encodebuffer (fis,  Bytearrayoutputstream);        string str =  Bytearrayoutputstream.tostring ();         fis.close ();         bytearraYoutputstream.close ();        return str;     }    public static void convertstringtoimage (String str,File  DestFile)  throws Exception {         Bytearrayinputstream bytearrayinputstream = new bytearrayinputstream (Str.getBytes ());         FileOutputStream fos = new  FileOutputStream (destfile);         base64decoder base64decoder  = new base64decoder ();         Base64decoder.decodebuffer (Bytearrayinputstream, fos);         Bytearrayinputstream.close ();         fos.close ();     }    }

Java Base64 Picture codec

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.