package com.javaIO.file;
import java.io.RandomAccessFile;
public class RandomAccessFileTest {
public static void main(String[] args) throws Exception {
Person p = new Person(23, "zhang", 1.89);
p.write();
p.read();
}
}
class Person {
int no;
String name;
double length;
public Person(int no, String name, double length) {
this.no = no;
this.name = name;
this.length = length;
}
public void write() throws Exception {
RandomAccessFile raf = new RandomAccessFile("rio.txt", "rw");
raf.writeInt(no);
raf.writeUTF(name);
raf.writeDouble(length);
raf.close();
}
public void read() throws Exception {
RandomAccessFile raf = new RandomAccessFile("rio.txt", "rw");
int n = raf.readInt();
String na = raf.readUTF();
double le = raf.readDouble();
raf.close();
System.out.println(" " + n + " " + na + " " + le);
}
}
JavaSE I/O RandomAccessFile类
最新推荐文章于 2014-10-19 22:14:50 发布