Code example for RandomAccessFile

Methods: close, readLine

0
    } 
     
    private long readLongFromFile(String filename) {
        RandomAccessFile f = null;
        try { 
            f = new RandomAccessFile(filename, "r");
            String contents = f.readLine();
            if (contents != null && contents.length() > 0) {
                return Long.parseLong(contents);
            } 
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
            if (f != null) try { f.close(); } catch (Exception e) { e.printStackTrace(); }
        } 
        return -1L; 
    } 
 
}