Java RandomAccessFile?÷?
???????????? ???????[ 2014/10/29 10:05:19 ] ????????Java ???? ????
????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();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11