Imam problem sa javom,
radim programcic za upisivanje podataka u fajl i iscitavanje objekata iz fajla,upisivanje radi dobro al nece mi procita stalno mi izbacuje gresku na readObject() funkciji
import java.io.*;
class podatci implements Serializable{
String ime;
String prezime;
int indeks;
}
class glavna{
public static void main(String args[])throws IOException
{
System.out.println("1 unos podataka");
System.out.println("2 pregled podataka");
BufferedReader kl=new BufferedReader(new InputStreamReader(System.in));
int oi=Integer.parseInt(kl.readLine());
if(oi==1){
BufferedReader un=new BufferedReader(new InputStreamReader(System.in));
System.out.println("unesite broj koliko studenata unosite");
int s=Integer.parseInt(un.readLine());
podatci [] gl=new podatci[s] ;
FileOutputStream kol=new FileOutputStream("fajl.txt");
ObjectOutputStream obj=new ObjectOutputStream(kol);
BufferedReader jo=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<s;i++){
gl=new podatci();
System.out.println("student");
System.out.println("ime");
gl.ime=jo.readLine();
System.out.println("prezime");
gl.prezime=jo.readLine();
System.out.println("indeks");
gl.indeks=Integer.parseInt(jo.readLine());
}
obj.writeObject(gl);
obj.flush();
kol.close();
}
else if(oi==2){
FileInputStream fis=new FileInputStream("fajl.txt");
ObjectInputStream dis=new ObjectInputStream(fis);
podatci[] ge= (podatci[]) dis.readObject();
for(int c=0;c<ge.length;c++){
System.out.println("student");
System.out.println("ime");
System.out.println(ge[c].ime);
System.out.println("prezime");
System.out.println(ge[c].prezime);
System.out.println("indeks");
System.out.println(ge[c].indeks);
}
fis.close();
System.out.println("kraj fajla");
}
}}