1,RandomAccessFile概述
-
RandomAccessFile类不属于流,是Object类的子类。但它融合了InputStream和OutputStream的功能。
-
支持对随机访问文件的读取和写入。
-
read(),write(),seek()
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Demo08_RandomAccessFile {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile("g.txt", "rw");
//raf.write(97);
//int x = raf.read();
//System.out.println(x);
raf.seek(0); //在指定位置设置指针
raf.write(98);
raf.close();
}
}