Archivos de Objetos y random...ayuda

ph
18 de Noviembre del 2007
Hola, aqui dejo el codigo de un programa; tengo problemas en los metodos la opcion 1 del switch y dela opticón 2, espero me puedan ayudar:

import java.io.*;
class Directorio implements Serializable{

private String nombre="";
private String dir="";
private String tel="";

public static void main (String arg []) {

byte option;

do{

System.out.println ("1-Crear directorio");
System.out.println ("2-Generar Reporte");
System.out.println ("3-Consultar");
System.out.println ("4-Salir");

System.out.println ("DIME CUAL");
option=Lectura.readByte();

Directorio d=new Directorio();

switch(option)
{
case 1: d.crearDirectorio();
break;
case 2: d.desplegarReporte();
break;
case 3: d.consultar();
break;
}

}while(option!=4);

}

public void crearDirectorio(){

FileOutputStream a= null;

ObjectOutputStream a2= null;

Directorio d2=null;//AGREGA

try{

a=new FileOutputStream("Directorio.dat");
a2=new ObjectOutputStream(a);

char sn;

do{
d2=new Directorio();//SE MOVIO

System.out.println ("NOMBRE");
d2.nombre=Lectura.readString();

System.out.println ("DIRECCION");
d2.dir=Lectura.readString();

System.out.println ("TELEFONO");
d2.tel=Lectura.readString();

a2.writeObject(d2); //ERROR

System.out.println ("MAS DATOS?");
sn=Lectura.readChar();

}while(sn=='s');
}//TRY

catch(IOException e){
System.out.println ("ERROR");
}
finally{
try{
a.close();
a2.close();
}
catch(IOException e){
System.out.println ("EROR AL CERRAR EL ARCHIVO");
}
}

}

public void desplegarReporte(){

FileInputStream a=null;

ObjectInputStream a2=null;

try{

a=new FileInputStream("Directorio.dat");

a2=new ObjectInputStream(a);

while(true){

a2.readObject();

Directorio d2=(Directorio) a2.readObject();

System.out.println ("NOMBRE: "+d2.nombre+" Direccion: "+d2.dir+" TELEFONO "+d2.tel);

}

}//TRY
catch(EOFException e){

System.out.println ("ARCHIVO VACIO");

}//CATCH

catch(IOException e){

System.out.println ("ERROR LEER");

}//CATCH
catch(ClassNotFoundException e){

System.out.println ("ERROR EN CLASE");

}//CATCH
finally{

try{
a.close();
a2.close();
}
catch(IOException e){
System.out.println ("EROR AL CERRAR EL ARCHIVO");
}

}

}

public void consultar(){

FileInputStream a=null;

ObjectInputStream a2=null;

try{

a=new FileInputStream("Directorio.dat");

a2=new ObjectInputStream(a);

System.out.println ("A QUIEN QUIERE BUSCAR");
String num2=Lectura.readString();

boolean z=true;

while(z)
{

Directorio d2=(Directorio) a2.readObject();

if(d2.nombre.equals(num2))
{
System.out.println ("TEL "+d2.tel+" DIRECCION "+d2.dir);
z=false;
}

}//While

}//Try

//+++
catch(EOFException e){

System.out.println ("ARCHIVO VACIO");

}//CATCH

catch(IOException e){

System.out.println ("ERROR LEER");

}//CATCH
catch(ClassNotFoundException e){

System.out.println ("ERROR EN CLASE");

}//CATCH

finally{

try{
a.close();
a2.close();
}
catch(IOException e){
System.out.println ("EROR AL CERRAR EL ARCHIVO");
}
}


}
}

tambien necesito si alguien me puede oriental con archivos random, los necesito para un trabajo