Mueyiwa Moses Ikomi Mueyiwa Moses Ikomi - 1 year ago 122
Android Question

How to read base64 String from Random Access File (Android)

i have a random access file that contains a base64 string


The problem is that when i read it using this code, i can't seem to return the exact thing that is in the text file.

File f = new File("fprint.txt");
RandomAccessFile randomFile = new RandomAccessFile(f, "rw");
String fromFile = randomFile.readLine();

When i log "fromFile", i get


Which is way shorter than what i put in. I want to able to read everything in the file the exact same way. Thank you

Edited: log code

Log.i("Check File", "Content of File: " + fromFile );

Answer Source

You should use read() method, instead of readLine(), for example:

public static String getBase64FromFile(String path) throws IOException {
    RandomAccessFile file = new RandomAccessFile(path, "r");
    String result = "";
    int b =;
    while (b != -1) {
        result = result + (char) b;
        b =;

    return result;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download