Vincent_87
10-12-2009, 20:29
Salve a tutti, mi sto da poco cimentando in Java ed è tutto il pomeriggio che sto sbattendo la testa su un problema: non mi riesce di importare oggetti da file. Il codice è il seguente:
public static TreeSetex<Item> item = new TreeSetex<Item>();
public static TreeSetex<Brand> brand = new TreeSetex<Brand>();
public static void main(String[] args) {
FileInputStream initem=null;
FileInputStream inbrand=null;
try {
initem= new FileInputStream("Item.bin");
inbrand= new FileInputStream("Brand.bin");
}catch(FileNotFoundException fnfe){
System.out.println("File non trovato");
System.exit(1);
}
ObjectInputStream sitem=null;
ObjectInputStream sbrand=null;
try{
sitem= new ObjectInputStream(initem);
sbrand= new ObjectInputStream (inbrand);
item=(TreeSetex<Item>) sitem.readObject();
brand=(TreeSetex<Brand>)sbrand.readObject();
sitem.close();
sbrand.close();
}catch(IOException ioe){
System.out.println("Errore in lettura dei file");
System.exit(1);
}catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException");
}
}
TreeSetex è semplicemente TreeSet che implementa Serializable.
I file Item.bin e Brand.bin creati a parte con eclipse vengono trovati senza problemi ma continua a darmi un IOException :confused:
public static TreeSetex<Item> item = new TreeSetex<Item>();
public static TreeSetex<Brand> brand = new TreeSetex<Brand>();
public static void main(String[] args) {
FileInputStream initem=null;
FileInputStream inbrand=null;
try {
initem= new FileInputStream("Item.bin");
inbrand= new FileInputStream("Brand.bin");
}catch(FileNotFoundException fnfe){
System.out.println("File non trovato");
System.exit(1);
}
ObjectInputStream sitem=null;
ObjectInputStream sbrand=null;
try{
sitem= new ObjectInputStream(initem);
sbrand= new ObjectInputStream (inbrand);
item=(TreeSetex<Item>) sitem.readObject();
brand=(TreeSetex<Brand>)sbrand.readObject();
sitem.close();
sbrand.close();
}catch(IOException ioe){
System.out.println("Errore in lettura dei file");
System.exit(1);
}catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException");
}
}
TreeSetex è semplicemente TreeSet che implementa Serializable.
I file Item.bin e Brand.bin creati a parte con eclipse vengono trovati senza problemi ma continua a darmi un IOException :confused: