Java
Chilkat2 Java
Get Contents of File as Base64
See more Encryption Examples
Demonstrates how to read the contents of a file and convert to a base64 string.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
public class ChilkatExample {
public static void main(String[] args) {
BinData bd = new BinData();
try {
bd.loadFile("qa_data/jpg/starfish.jpg");
} catch (ChilkatException e) {
System.out.println("Failed to load file.");
return;
}
System.out.println(bd.getEncoded("base64"));
// If you want mult-line base64:
System.out.println("--");
System.out.println(bd.getEncoded("base64_mime"));
// If you want hex..
System.out.println("--");
System.out.println(bd.getEncoded("hex"));
// etc..
}
}