//use randomAccessFile Class
RandomAccessFile in =new RandomAccessFile(fileName);
//then you may call the method of readBye readInt readLine etc
//of RandomAccessFile class
//for example in.readByte
public class readData
{
public static void main(String[] args)
{
BufferedReader in=new BufferedReader(new FileReader("你的文件名.txt"));
String s;
int i=0;
while((s=in.readLine())!=null)
{
StringTokenizer t=new StringTokenizer(s,"|");//"|"为分隔符
p[i].id=Integer.parseInt(t.nextToken());//将第一个记录赋给变量id
p[i].name=t.nextToken();//将第二个记录赋给变量name
p[i].age=Integer.parseInt(t.nextToken());//将第三个记录赋给变量age
p[i].sex=t.nextToken();//将第四个记录赋给变量sex
i++;
}
in.close();
}
}
//**********************************************************
我假设你要赋值得变量结构如下:
class p
{
public int id;
public String name;
public int age;
public String sex;
}