|
Исходный текст программы RandomAccess.java
|
Оглавление |
Назад
// ==========================================
// RandomAccess.java
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.io.*;
import java.util.*;
public class RandomAccess
{
public static void main(String args[])
{
int i;
System.out.println(
"* Random Access File demonstration\n");
RandomAccessFile data;
long dataPointer = 0;
Vector idx = new Vector();
String s;
try
{
data =
new RandomAccessFile(
"direct.dat", "rw");
for(i = 0; i < 10; i++)
{
dataPointer = data.getFilePointer();
idx.addElement(new Long(dataPointer));
data.writeBytes("Record " + i + "\n");
}
for(i = 9; i >= 0; i--)
{
dataPointer = (long)
((Long)idx.elementAt(i)).doubleValue();
data.seek(dataPointer);
s = data.readLine();
System.out.println(s);
}
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}
|
|