Originariamente inviato da angelo85ct
questa invece è la funzione relativa al caricamento dei dati nella linkedlist:
float valuta=0;
int id=0;
String nome, cognome;
boolean trovato=true;
LinkedList pippo = new LinkedList();
//metodo per la lettura del secondo file
char tipoper='x';
try{
BufferedReader tex=new BufferedReader(new FileReader("movimenti.txt"));
StringTokenizer cl=new StringTokenizer(tex.readLine(), " ");//separa tra gli spazi
while (cl.hasMoreTokens()){
StringTokenizer cl1=new StringTokenizer(cl.nextToken(), ";");
if(cl1.hasMoreTokens()==true)
id=Integer.parseInt(cl1.nextToken());
if(cl1.hasMoreTokens()==true)
tipoper=cl1.nextToken().charAt(0);
if(cl1.hasMoreTokens()==true)
valuta=Float.parseFloat(cl1.nextToken());
movimenti t=new movimenti(id,tipoper,valuta);
t.stampa1();
pippo.add(t);
}
}
catch(FileNotFoundException e)
{trovato=false;}
catch(IOException e)
{System.out.println ("Errore lettura file "); }
if (!trovato)
System.out.println("FILE clienti.txt NON TROVATO");
else
System.out.println("\nFILE clienti.txt CARICATO CON SUCCESSO \n\n");
Iterator g =pippo.iterator();
while(g.hasNext()){
System.out.println(((movimenti)g.next()).toString( ));
}