RAF中指针的操作与移动
package com.tedu.raf;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RafSeekDemo {
public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile("abc.txt", "rw");
long pos = raf.getFilePointer();
System.out.println("指针所在位置pos:" + pos);
int max = Integer.MAX_VALUE;
raf.write(max>>>24);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
raf.write(max>>>16);
raf.write(max>>>8);
raf.write(max);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
raf.writeLong(123L);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
raf.writeDouble(123.123);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
raf.seek(0);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
int i = raf.readInt();
System.out.println(i);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
raf.seek(4);
long l = raf.readLong();
System.out.println(l);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
double d= raf.readDouble();
System.out.println(d);
System.out.println("指针所在位置pos:" + raf.getFilePointer());
System.out.println("程序结束!");
raf.close();
}
}