WRITE:
public static void randomWrite(String path){ RandomAccessFile raf=null; try { raf = new RandomAccessFile(path, "rw"); raf.seek(raf.length()); raf.write(" 追加内容".getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
READ:
randomAccessFile.seek(this.randomAccessFile.length()-getRecordSize()-length); byte[] b = new byte[getRecordSize()]; this.randomAccessFile.readFully(b); String line = new String(b, Config.DB_CHARACTER_ENCODING);