From http://commons.apache.org/proper/commons-codec/download_codec.cgi
Download commons-codec-1.9-bin.zip unzip get the commons-codec-1.9.jar to add the jar package to the Java project created by ECLIPSE, You can reference the classes provided in the jar package.
Public interface binarydecoder extends decoder interface can also inherit the parent interface
Base64.java source code path:
Commons-codec-1.9-src \ SRC \ main \ Java \ org \ apache \ commons \ codec \ binary \ base64.java
Because base64 directly operates byte streams, rather than bytes streams, this class is thread-safe.
The standard encoding table consists of 26 uppercase letters, 26 lowercase letters, 0-9 +/64 characters in total.
Import Java. io. file; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. fileoutputstream; import Java. io. ioexception; import javax. imageIO. stream. fileimageoutputstream; import Org. apache. commons. codec. binary. base64; public class base64demo_01 {public static void main (string [] ARGs) throws filenotfoundexception {// convert the image file to a byte array, encode it with base64: file = new file ("C: \ a.jpg"); fileinputstream fin = NULL; byte [] DATA = NULL; try {fin = new fileinputstream (File); Data = new byte [Fin. available ()]; Fin. read (data); Fin. close ();} catch (exception e) {e. printstacktrace ();} // view the encoding and generate the string encodestr = base64.encodebase64string (data); system. out. println (encodestr); file OUTFILE = new file ("C: \ save.txt"); fileoutputstream Fos = new fileoutputstream (OUTFILE); try {FOS. write (encodestr. getbytes (); FOS. flush (); FOS. close ();} catch (ioexception e) {e. printstacktrace ();} // Byte encoding byte [] encodeimage = base64.encodebase64 (data); // generate the encoded jpg image file imgfile = new file ("C: \ B .jpg "); try {fileimageoutputstream fos1 = new fileimageoutputstream (imgfile); fos1.write (encodeimage); fos1.flush (); fos1.close ();} catch (ioexception e) {e. printstacktrace ();} system. out. println ();}}