hola ragazzi, ho un problema per aggiungere dei valori in un file usando l'hashmap, ecco il mio codice:
come vedete dal codice se il file è presente stampo i valori che ci sono dentro (vedi il codice rosso), altrimenti lo creo questo file e salvo dentro dei valori.codice:File creazione = new File("conticorrenti.out"); if (creazione.exists()){ FileInputStream file = new FileInputStream("conticorrenti.out"); ObjectInputStream in = new ObjectInputStream(file); try { Object oggetti = in.readObject(); HashMap HashOggetti = (HashMap) in.readObject(); System.out.println(" 359 lettura "+ HashOggetti.size()); Set<Map.Entry<Integer, ContoBancoPostaConFido>> set = HashOggetti.entrySet(); for (Map.Entry<Integer, ContoBancoPostaConFido> me : set) { System.out.print(me.getKey() + ": "); System.out.println(me.getValue().getCorrentista()); System.out.println("Numero Conto: "+me.getValue().getNumeroConto()); System.out.println("Stampa Conto: "+me.getValue().stampaConto()); } } catch (ClassNotFoundException e) { e.printStackTrace(); } } else{ FileOutputStream file = new FileOutputStream("conticorrenti.out"); ObjectOutputStream out = new ObjectOutputStream(file); System.out.println("salvaconti 355 " + out.toString().toString()); out.writeObject(nuovoConto); out.writeObject(dbContiCorrente);} }
La mia domanda è: come faccio ad aggungere altri valori nel file presente???

Rispondi quotando