Question

The application of Base64 encoding that I have read was to convert binary data or some string in to Base64 format. But I came to know of files (example: PDF, Excel) themselves Base64 encoded which can't be even opened/supported by respective software.

My questions are:

  1. Can we encode whole files in to Base64.
  2. What is the application scenario of this.
  3. Can we know by looking at the content which decoder to use.

(FYI: I have read wiki Base64 )

No correct solution

OTHER TIPS

Base64 decoding in Java and i think encoding also can done with some classes in this package

package is

import org.apache.commons.codec.binary.Base64;

and the logic is

 String filepath = "C:\\Users\\sandeep\\somefile";
    String encodedString = null;

    try {
        File file=new File(filepath);
        FileReader fr = new FileReader(file);
        BufferedReader reader = new BufferedReader(fr);

        while ((encodedString = reader.readLine()) != null) {

            byte[] binOfEncoded = Base64.decodeBase64(encodedString.getBytes());  
            System.out.println("Base64 Decoded  String     :       " + binOfEncoded);               
        }

    } catch (IOException x) {
        System.err.format("IOException: %s%n", x);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top