Code example for RandomAccessFile

Methods: length, readLine

0
} 
 
// Returns an ASCII decimal number read from the specified file, -1 on error. 
private static long readNumber(String filename) {
    try { 
        RandomAccessFile f = new RandomAccessFile(filename, "r");
        try { 
            Log.d(LOGGING_TAG, "f.length() = " + f.length());
            String contents = f.readLine();
            if(!contents.isEmpty() && contents!=null) {
                try { 
                    return Long.parseLong(contents);
                } 
                catch(NumberFormatException nfex) {
                    Log.w(LOGGING_TAG, "File contents are not numeric: " + filename); 
                } 
            } 
            else { 
                Log.w(LOGGING_TAG, "File contents are empty: " + filename); 
            } 
        }