Java picture file Base64 encoding and binary encoding format convert each other

Source: Internet
Author: User
Tags base64

1      Public Static byte[] Base64string2bytefun (String base64str) {2Base64decoder decoder =NewBase64decoder ();3         byte[] B =NULL;4         Try {5b =Decoder.decodebuffer (BASE64STR);6              for(inti = 0; i < b.length; ++i) {7                 if(B[i] < 0) {8B[i] + = 256;9                 }Ten             } One}Catch(IOException e) { A e.printstacktrace (); -         } -          the         returnb;  -     } -      Public Staticstring Getimagestr (String imgfile) { -InputStream InputStream =NULL; +         byte[] data =NULL; -         Try { +InputStream =NewFileInputStream (imgfile); Adata =New byte[Inputstream.available ()]; at inputstream.read (data); - inputstream.close (); -}Catch(IOException e) { - e.printstacktrace (); -         } -Base64encoder encoder =NewBase64encoder (); in         returnEncoder.encode (data); -}

Tips:

Sun.misc.BASE64Encoder cannot find a solution to the jar package

Right-click Project-"Properties-" Java bulid path-"JRE System library-" Access rules-"Resolution select accessible, fill in the below * * OK!!!

Java picture file Base64 encoding and binary encoding format convert each other

Related Article

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.