package demo.io;
import java.io.IOException;
import java.io.RandomAccessFile;
class 随机访问文件RandomAccessFile {
public static void main(String[] args) throws IOException {
outputFile();
inputFile();
}
private static void inputFile() throws IOException {
RandomAccessFile raf = new RandomAccessFile("后期设备的配置文件.properties", "r");
System.out.println("文件长度(字节):" + raf.length());
byte[] buf = new byte[4];
raf.read(buf);
System.out.println(new String(buf));
System.out.println("目前指针位置: " + raf.getFilePointer());
raf.close();
}
private static void outputFile() throws IOException {
RandomAccessFile raf = new RandomAccessFile("后期设备的配置文件.properties", "rw");
raf.write("张三".getBytes());
raf.write("李四".getBytes());
raf.close();
}
}