Hi,Michael :
Thank you,I have understood.
but the new question occur,I write the codes is follow:
import java.io.*;
import java.util.*;
class TestRandomAccessFile
{
private static int headerLen;
private static int recordLen = 1;
private static int recordCount;
private static RandomAccessFile db;
public static void main(String[] args)
throws IOException
{
File f = new File(args[0]);
byte byteArray[] = null;
if (f.exists() && f.canRead() && f.canWrite()) {
db = new RandomAccessFile(f, "r");
System.out.println(db.readInt());
int iii=db.readInt();
System.out.println(iii);
short ii=db.readShort();
System.out.println(ii);
short lengthShort[] = new short[ii];
for (short i=0;i<ii ;i++ )
{
int a = db.readShort();
System.out.println(a);
byteArray = new byte[a];
db.readFully(byteArray);
System.out.println(new String(byteArray));
lengthShort[i] = db.readShort();
System.out.println(lengthShort[i]);
}
for (int i=0;i<iii ;i++ )
{
System.out.print(db.readShort()+" ");
for (int aa=0;aa<lengthShort.length ;aa++ )
{
byte temp[] = new byte[lengthShort[aa]];
db.readFully(temp);
System.out.print(new String(temp)+" ");
}
System.out.println();
}
} else {
throw new IOException("Data: request to open non-existant or " +
"inaccessible file" + args[0]);
}
}
}
the above codes can read all date(information) is right.
but occur Exception follow:
514
70
6
4
name
32
8
location
64
11
specialties
64
4
size
6
4
rate
8
5
owner
8
0 Dogs With Tools Smallville //more date(field)in a record
0 Hamner & Tong Smallville ......
0 Philharmonic Remodeling Whoville ......
0 Fred & Nobby Whoville ......
0 Dogs With Tools Whoville ......
0 Dogs With Tools Metropolis ......
0 Bitter Homes & Gardens Metropolis ......
0 Philharmonic Remodeling Metropolis ......
0 Dogs With Tools Pleasantville ......
0 Moore Power Tool Ya Pleasantville ......
0 Swanders & Flaughn Digitopolis ......
0 Fred & Nobby Digitopolis ......
0 Hamner & Tong Atlantis ......
0 Moore Power Tool Ya Atlantis ......
0 Hamner & Tong EmeraldCity ......
0 Bitter Homes & Gardens EmeraldCity ......
0 Dogs With Tools Bali Hai
0 Fred & Nobby Bali Hai ......
0 Hamner & Tong Xanadu ......
0 Moore Power Tool Ya Xanadu ......
0 Philharmonic Remodeling Xanadu ......
0 Buonarotti & Company Paravel ......
0 Hamner & Tong Paravel ......
0 Philharmonic Remodeling Hobbiton ......
0 Buonarotti & Company Hobbiton ......
0 Dogs With Tools Lendmarch ......
0 Buonarotti & Company Lendmarch ......
0 Swanders & Flaughn Lendmarch ......
Exception in
thread "main" java.io.EOFException
at java.io.RandomAccessFile.readShort(Unknown Source)
at TestRandomAccessFile.main(TestRandomAccessFile.java:39)
The format of data in the database file is as follows:
Start of file
4 byte numeric, magic cookie value identifies this as a data file
4 byte numeric, offset to start of record zero
2 byte numeric, number of fields in each record
Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block
Data section. (offset into file equal to "offset to start of record zero" value)
Repeat to end of file:
2 byte flag. 00 implies valid record, 0x8000 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
End of file
How to solved?