这篇文章主要介绍“Java中RandomAccessFile类怎么随机访问”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Java中RandomAccessFile类怎么随机访问”文章能帮助大家解决问题。
1、过程
(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类怎么随机访问”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注编程之家行业资讯频道,小编每天都会为大家更新不同的知识点。