Sample code for 30+ languages & platforms
Java

Base64 Encode a File

_LANGUAGE_ to Base64 encode the contents of a file.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.FileAccess;

public class ChilkatExample {

    public static void main(String[] args) {
        // Get the contents of a file into a base64 encoded string:
        FileAccess fac = new FileAccess();
        String strBase64;
        try {
            strBase64 = fac.readBinaryToEncoded("c:/data/something.pdf", "base64");

            // Now write the string to a file:
            fac.writeEntireTextFile("c:/data/something_pdf_base64.txt", strBase64, "us-ascii", false);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Success!");
    }
}