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