星空网 > 软件开发 > Java

[javaSE] IO流(RandomAccessFile)

随机访问文件,可以看作一个大型的byte[]数组,不算是IO体系中的一员,内部封装了字节输入输出流,可以设置权限,可以调整指针的位置

 

获取RandomAccessFile对象,构造参数:String文件名称,String的文件模式

调用RandomAccessFile对象的write()方法,参数:byte[]数组

 

获取RandomAccessFile对象,构造参数:String文件名称,String的文件模式

调用RandomAccessFile对象的seek()方法,调整指针位置,参数:int的索引位置

调用RandomAccessFile对象的skipBytes()方法,可以跳过指定索引,参数:int索引位置

 

线程下载的原理就是使用这个类

import java.io.RandomAccessFile;public class RandomAccessFileDemo {  /**   * @param args   * @throws Exception   */  public static void main(String[] args) throws Exception {    //写入    RandomAccessFile raf=new RandomAccessFile("test2.txt", "rw");    raf.write("陶士涵李小明".getBytes());    raf.close();    //读取    readFile();  }  public static void readFile() throws Exception{    RandomAccessFile raf=new RandomAccessFile("test2.txt", "rw");    raf.seek(6);//调整指针位置    byte[] b=new byte[1024];    int len=raf.read(b);    raf.close();    System.out.println(new String(b,0,len));//输出 李小明  }}

 




原标题:[javaSE] IO流(RandomAccessFile)

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

菲律宾寄中国:https://www.goluckyvip.com/tag/96919.html
Shopify优势:https://www.goluckyvip.com/tag/9692.html
菲律宾快递费:https://www.goluckyvip.com/tag/96920.html
连云港寄菲律宾用什么快递好:https://www.goluckyvip.com/tag/96921.html
福建快递到菲律宾运费:https://www.goluckyvip.com/tag/96923.html
快递往菲律宾:https://www.goluckyvip.com/tag/96924.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流