1、過程
(1)既可以充當一個輸入流, 也可以沖淡一個輸出流
(2)支援從檔案的開頭讀取、寫入
(3)支援從任意位置的讀取、寫入(插入)
#(4)RandomAccessFile類別需要指定的存取模式:
2、實例
public void RandomAccessFile(String src, String srcMode, String dest, String destMode) { RandomAccessFile accessFile = null; RandomAccessFile accessFile1 = null; try { accessFile = new RandomAccessFile(new File(src), srcMode); accessFile = new RandomAccessFile(new File(dest), destMode); byte[] bytes = new byte[1024]; int length; while ((length = accessFile.read(bytes)) != -1) { accessFile1.write(bytes, 0, length); } } catch (IOException e) { e.printStackTrace(); } finally { if (accessFile != null) try { accessFile.close(); } catch (IOException e) { e.printStackTrace(); } if (accessFile1 != null) { try { accessFile1.close(); } catch (IOException e) { e.printStackTrace(); } } } }
以上是Java中RandomAccessFile類別怎麼隨機訪問的詳細內容。更多資訊請關注PHP中文網其他相關文章!