public static String encodeFromFile(final String filename) {

        java.io.File file = new java.io.File(filename);
        long fileLength = file.length();

        java.io.InputStream ins;
        try {
            ins = new java.io.FileInputStream(file);
        } catch (FileNotFoundException e) {
            System.out.println("Error opening file " + filename + e.getMessage());
            return null;
        }
        String encodedData = encodeFromInputStream(ins, fileLength);
        if (encodedData == null) {
            System.err.println("Error encoding from file " + filename);
        }
        return encodedData;
    }
public static String encodeFromFile ( final String filename ) { java . io . File file = new java . io . File ( filename ) ; long fileLength = file . length ( ) ; java . io . InputStream ins ; try { ins = new java . io . FileInputStream ( file ) ; } catch ( FileNotFoundException e ) { System . out . println ( "Error opening file " + filename + e . getMessage ( ) ) ; return null ; } String encodedData = encodeFromInputStream ( ins , fileLength ) ; if ( encodedData == null ) { System . err . println ( "Error encoding from file " + filename ) ; } return encodedData ; }
Convenience method for reading a binary file and base64-encoding it.

@param filename
Filename for reading binary data
@return base64-encoded string or null if unsuccessful
@since 2.1