questa è la mia classe:
import java.lang.*;
import java.io.*;
import java.util.*;
public class movimenti{
public int id;
public char tipoper;
public float valuta=0;
public movimenti(int id, char tipoper, float valuta){
this.id=id;
this.tipoper=tipoper;
this.valuta=valuta;
}
public void stampa1(){
System.out.println(this.id+" - "+this.tipoper+" "+this.valuta);
}
public String toString(){
return "ID: [" + id + "]\toperazione: " + tipoper+"\t"+valuta; }
public int getId(){
return id; }
public float getValuta(){
return valuta; }
public int id(){
return id; }
public char getOper(){
return tipoper; }
}
qui è dove carico il file nella linked listfile del tipo <id>;<tipooperazione>;<valuta> <id><>.......)
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()){
//while (cl!=null){
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( ));
}
Ora il Nocciolo della questione è che io nn riesco a fare la seguente:
salvare tutte le informazioni su un file salvando su un file binario (il cui nome viene specificato da tastiera) il totale dei versamenti di ogni id, in accordo al formato <id1><totale1><id2><totale2>