Java tutorial
//package com.java2s; //License from project: Apache License import android.util.Base64; import java.io.File; import java.io.FileInputStream; public class Main { public static String encodeToFile(File file) { try { FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer); inputFile.close(); return Base64.encodeToString(buffer, Base64.NO_WRAP); } catch (Exception e) { e.printStackTrace(); } return null; } public static String encodeToString(String content) { try { return Base64.encodeToString(content.getBytes(), Base64.NO_WRAP); } catch (Exception e) { e.printStackTrace(); } return ""; } }