日期:2014-05-20 浏览次数:20705 次
import java.io.File; import java.io.RandomAccessFile; public class RandomAcessFileDemo { public static void main(String[] args) throws Exception { File f = new File("temp.txt"); RandomAccessFile raf = null; raf = new RandomAccessFile(f, "rw"); String name = "zhangsan"; Integer age = 15; raf.writeBytes(name); raf.skipBytes(8); raf.writeInt(age); raf.seek(0);//找位置 byte[] b = new byte[8]; raf.read(b); System.out.println(new String(b)); System.out.println(raf.readInt()); raf.close(); } }