How to Encode a file with Base64 Encoding in Java

By Rohit Nirmal
We will use static method in "Base64Convert.java". Use the following line in your Java program:

Base64Convert.encode ( file_in, file_out)

or on command line

java Base64Convert "encode" file-in-path file-out-path

This program will insert only LF after 76 characters on each line in the output file except the last line. The last line will end in = or == as the base 64 specs stipulate.

How to Decode a file that has Base64 Encoded data (Java)


We will use static methods in class Bas64Convert. Use the following code:

Base64Convert.decode ( file_in, file_out)

or on command line

java Base64Convert "decode" file-in-path file-out-path


Click here to download base64.zip that contains Base64Convert.java.