Java tutorial
//package com.java2s; import org.apache.commons.codec.binary.Base64; import java.io.File; import java.io.FileInputStream; public class Main { public static String FiletoBase64(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer); inputFile.close(); return new String(Base64.encodeBase64(buffer)); } }