RandomAccessFile

      WRITE:
public
static void randomWrite(String path){ RandomAccessFile raf=null; try { raf = new RandomAccessFile(path, "rw"); raf.seek(raf.length()); raf.write("\r\n追加内容".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);

 

posted @ 2017-10-10 18:06  kakaisgood  阅读(100)  评论(0编辑  收藏  举报