Quantcast
Channel: Java mon amour
Viewing all articles
Browse latest Browse all 1124

Minimalistic Java application to encode/decode in Base64

$
0
0
If your Outlook blocks all kind of attachments, you have here the FINAL resolution to the problem (Outlook doesn't check for Base64 text attachments)



import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

public class Decoder {

    public static void main(String[] args) throws Exception {
        if (args.length < 3) {
            System.out.println("Usage: java EncodeFileWithBASE64 d|e ");
            return;
        }
        String op = args[0];
        String inputFile = args[1];
        String outputFile = args[2];


        if (op.equalsIgnoreCase("e")) {
            BASE64Encoder encoder = new BASE64Encoder();
            encoder.encode(
                    new FileInputStream(inputFile),
                    new FileOutputStream(outputFile)
            );
        } else {
            BASE64Decoder decoder = new BASE64Decoder();
            decoder.decodeBuffer(new FileInputStream(inputFile),
                    new FileOutputStream(outputFile));


        }
    }
}






If you put in in Eclipse you get an error, and this is how to solve it: http://stackoverflow.com/questions/5549464/import-sun-misc-base64encoder-results-in-error-compiled-in-eclipse (it's easier to ignore errors than using an Apache Commons library)


Viewing all articles
Browse latest Browse all 1124

Trending Articles