import java.io.*;
class RandomAccessFileDemo
{
public static void main(String[] args) throws IOException
{
//writeFile();
readFile();
}
public static void readFile() throws IOException
{
RandomAccessFile raf = new RandomAccessFile("hebin.txt","r");
raf.seek(9);
byte[] buf = new byte[4];
raf.read(buf);
String name = new String(buf);
int age = raf.read();
System.out.println(name);
System.out.println(age);
raf.close();
}
public static void writeFile() throws IOException
{
RandomAccessFile raf = new RandomAccessFile("hebin.txt","rw");
raf.write("lisi".getBytes());
raf.writeInt(258);
raf.write("wangwu".getBytes());
raf.write(99);
raf.close();
}
}
raf.seek(9);里面到底该传多少才能取出wangwu的数据啊? |