Code example for RandomAccessFile

Methods: close, setLength

0
            // Write the hash to file 
            RandomAccessFile raf = new RandomAccessFile(name, "rw");
            // Truncate the file if pattern is null, to clear the lock 
            if (hash == null || hash.length == 0) {
                raf.setLength(0);
            } else { 
                raf.write(hash, 0, hash.length);
            } 
            raf.close();
        } catch (IOException ioe) {
            Slog.e(TAG, "Error writing to file " + ioe);
        } 
    } 
 
    private void writeToDb(String key, String value, int userId) {
        ContentValues cv = new ContentValues();
        cv.put(COLUMN_KEY, key);
        cv.put(COLUMN_USERID, userId);
        cv.put(COLUMN_VALUE, value);
 
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();