????RandomAccessFile
????RandomAccessFile????????????Щ?????????????????????????seek( )???????????????????ж?д?????Щ??????С????????????????С??λ?????????????????????????????
????RandomAccessFile??????InputStream??OutputStream???????????????????DataInput?? DataOutput??????(DataInputStream??DataOutputStream???????????????)????????????????????????????????InputStream??OutputStream?????????????κι?????????????????????????з???(???????????????????)????????д?????????????RandomAccessFile??????????????????????????????????????I/O????Щ???????????????????????????????Object???????????
???????????RandomAccessFile?????????????DataInputStream??DataOutputStream??????????????????????Щ?????????綨λ???getFilePointer( )???????????????seek( )??????ж??????С??length( )??skipBytes()?????????????????????????????????????????????("r")?????????д???("rw")?????????? (??C??fopen( )?????)??????????д?????
???????RandomAccessFile????seek???????????????????????????????BufferedInputStream?????mark( )??????????????????趨???(??????????????????????)??????????reset( )???????λ????????????????????????????????á?
????RandomAccessFile?????????????????????????????JDK 1.4??nio??"?????????(memory-mapped files)"????????????????????????"?????????"??????RandomAccessFile???
import java.io.IOException;
import java.io.RandomAccessFile;
public class TestRandomAccessFile {
public static void main(String[] args) throws IOException {
RandomAccessFile rf = new RandomAccessFile("rtest.dat"?? "rw");
for (int i = 0; i < 10; i++) {
//д?????????double????
rf.writeDouble(i * 1.414);
}
rf.close();
rf = new RandomAccessFile("rtest.dat"?? "rw");
//???????????????5??double???????
rf.seek(5 * 8);
//?????6??double????
rf.writeDouble(47.0001);
rf.close();
rf = new RandomAccessFile("rtest.dat"?? "r");
for (int i = 0; i < 10; i++) {
System.out.println("Value " + i + ": " + rf.readDouble());
}
rf.close();
}
}&nbsp;