ally
20-09-2004, 16:56
...allora il problema è questo...
...costruisco un bean legato ad hash map pescando elementi da un file di testo....
public static FilmsContainer recuperaElencoFilm()
{FilmsContainer container = new FilmsContainer();
try {
FileReader file = new FileReader("ElencoFilm1.txt");
BufferedReader buff = new BufferedReader(file);
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else {
FilmBean film = new FilmBean();
String vett[] = ((String)line).split("#");
film.setCodice(vett[0]);
film.setTitolo(vett[1]);
film.setGenere(new Integer(vett[2]));
film.setDurata(vett[3]);
container.setFilm(film);
}
}
buff.close();
} catch (IOException e) {
System.out.println("Errore " + e.toString());
}
return container;
}
...ora se devo inserire un nuovo elemento come faccio?
...costruisco un bean legato ad hash map pescando elementi da un file di testo....
public static FilmsContainer recuperaElencoFilm()
{FilmsContainer container = new FilmsContainer();
try {
FileReader file = new FileReader("ElencoFilm1.txt");
BufferedReader buff = new BufferedReader(file);
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else {
FilmBean film = new FilmBean();
String vett[] = ((String)line).split("#");
film.setCodice(vett[0]);
film.setTitolo(vett[1]);
film.setGenere(new Integer(vett[2]));
film.setDurata(vett[3]);
container.setFilm(film);
}
}
buff.close();
} catch (IOException e) {
System.out.println("Errore " + e.toString());
}
return container;
}
...ora se devo inserire un nuovo elemento come faccio?