package p10;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* RAf提供了方便读写基本类型数据的方法
* @author Administrator
*
*/
public class after {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
RandomAccessFile raf
=new RandomAccessFile("d:/hao.txt", "rw");
/*
* 向文件中写入一个int最大值
* 原型:write(byte b)
*/
int max=Integer.MAX_VALUE;
//写入max,每次写入一个字节
raf.write(max>>>24);
raf.write(max>>>16);
raf.write(max>>>8);
raf.write(max);
//
raf.writeInt(98);
raf.writeDouble(98.1);
raf.writeLong(198l);
raf.writeChar('q');
raf.writeChars("hellop");//字符间有空格
raf("xutaoXutAO".getBytes());//没空格
raf.close();
//api
RandomAccessFile raf2
=new RandomAccessFile("d:/hao.txt", "rw");
/*
* long getFilePointer()/0,1,2,3
*/
raf2.readInt();
System.out.println(raf2.getFilePointer());
//移动指针
raf2.seek(3);//指向第四个字节
System.out.println(raf2.read());//读取一个字节转换成int
}
}