当前位置: 技术问答>java相关
哪位大侠帮我讲讲RandomAccessFile类是干什么的?和用法
来源: 互联网 发布时间:2015-02-27
本文导语: | 这个类用于一个文件读写的随机访问。 import java.io.*; public class RanFile { public static void main(String[] arg) { try { RandomAccessFile rf = new RandomAccessFile("ranfile.data","rw"); rf.writeChars("abcdefu04F5"); long position...
|
这个类用于一个文件读写的随机访问。
import java.io.*;
public class RanFile {
public static void main(String[] arg) {
try {
RandomAccessFile rf =
new RandomAccessFile("ranfile.data","rw");
rf.writeChars("abcdefu04F5");
long position = rf.getFilePointer();
rf.writeDouble(3.1415);
rf.writeUTF("abcdefu04F5");
rf.seek(position);
System.out.println(rf.readDouble());
rf.seek(0L);
for(int i=0; i
import java.io.*;
public class RanFile {
public static void main(String[] arg) {
try {
RandomAccessFile rf =
new RandomAccessFile("ranfile.data","rw");
rf.writeChars("abcdefu04F5");
long position = rf.getFilePointer();
rf.writeDouble(3.1415);
rf.writeUTF("abcdefu04F5");
rf.seek(position);
System.out.println(rf.readDouble());
rf.seek(0L);
for(int i=0; i