Pensandoci è un database...
e nel database c'è solo un metodo che praticamente salva con stream e salva lo stesso oggetto... riporto il tutto... se mi dai un parere su come è scritto mi farebbe piacere...
Ti ringrazio di tutto...
...
@SuppressWarnings("unchecked")
public void load(String nomeFile) {
try {
FileInputStream in = new FileInputStream(name);
ObjectInputStream obj = new ObjectInputStream(in);
a = (TreeMap<B,C> )obj.readObject();
obj.close();
in.close();
}catch(FileNotFoundException e) {
System.out.println(e.getMessage());
}catch (StreamCorruptedException e) {
System.out.println("Formato file non valido!");
}catch (ClassCastException e) {
System.out.println("Il file non contiene un database!");
}catch(IOException e) {
System.out.println(e.getMessage());
}catch(ClassNotFoundException e) {
System.out.println(e.getMessage());
}
}public void load(String name) {
...
...
public File print(String name) {
File file = new File(name);
try {
FileOutputStream out = new FileOutputStream(file);
PrintStream print = new PrintStream(out);
Iterator it = m.keySet().iterator();
B b;
C c;
while (it.hasNext()) {
b = (B) it.next();
c= getC(b);
ps.println(b.toString() + " " + c.toString());
}
}catch(AException e) {
System.out.println(e);
}catch(IOException e) {
System.out.println(e);
}
return file;
}
...
Ma se viene caricato un file inesistente, o che non contanga una treemap penso che stampi un errore dato che c'è il try o no? In caso come dovrei modificare? Che altre eccezioni potrebbero verificarsi?
Ciao

Rispondi quotando