I'm using Eclipse. I have the following line of code:
wr.write(new sun.misc.BASE64Encoder().encode(buf));
Eclipse marks this line as an error. I imported the required libraries:
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
But again, both of them are shown as errors. I found a similar post here.
I used Apache Commons as the solution suggested by including:
import org.apache.commons.*;
and importing the JAR files downloaded from: http://commons.apache.org/codec/
But the problem still exists. Eclipse still shows the errors previously mentioned; please advise.
Use Java 8's never-too-late-to-join-in-the-fun class:
java.util.Base64
To convert this you need Encoder & Decoder which you will get from http://www.source-code.biz/base64coder/java/. It is File Base64Coder.java you will need.
Now to access this class as per your requirement you will need class below:
In Android you can convert your Bitmap to Base64 for Uploading to Server/Web Service.
This “encodedImage” is text representation of your Image. You can use this for either uploading purpose or for diplaying directly into HTML Page as below (Reference):
Documentation: http://dwij.co.in/java-base64-image-encoder
In Java 7 I coded this method
apache commons has nice implementation of base64. you can do this as simply as
you can find more details about base64 encoding at http://faisalbhagat.blogspot.com/2014/06/base64-encoding-using-java-and.html