//字符流 高级流有缓存 flush() 流用完之后要关闭 close();
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
RandomAccessFile raf = new RandomAccessFile("d:\\b.txt", "rw");
raf.seek(2);
raf.write("abc".getBytes());
//
raf.seek(2); //绝对,从位置0开始
raf.skipBytes(2); // 相对,从当前位置开始
raf.write("天下".getBytes());
raf.seek(5);
//创建1KB缓存进行读取提高性能
byte[] bytes = new byte[1024];
int i = raf.read(bytes);
raf.seek(4);
int t1 = raf.read();
int t2 = raf.read();
System.out.println(t1+" "+t2);
System.out.println(new String(bytes, 0, i));
raf.close();
}
RandomAccessFile随机访问文件,可读可写
最新推荐文章于 2023-04-23 21:34:04 发布