Page 1393 - Informatica dalla A a Z
P. 1393

System.exit (l);

                  }
                  c = new Contatto();
                  try
                  {
                          s = fIN.readLine( );
              / / legge e stampa una riga
                          while ( s ! = null)
                          {
                               st = new StringTokenizer ( s, ";");
                                c.cognome = st .nextToken( );
                                c.nome = st .nextToken( );
                                c.telefono = st .nextToken( );
                                c.stampa( );
                                s = fIN.readLine( );
                          }
                   }
                   catch (IOException e)
                   {

                          System.out .println("Errore nella lettura del file.");
                          System.exit (1);
                   }
                   try
                     {
                        f.close( );
                   }
                   catch (IOException e )
                   {
                          System.out.println("Errore nella chiusura del file.");
                          System.exit(1);
                   }
                   public static void main(String argv[ ] )
                   {
                          LeggiAgenda a = new LeggiAgenda( );
                          a.leggeToken( );
                    }
              }





           Vediamo ora come utilizzare contemporaneamente uno stream di input e uno di output.
           Esercizio: Eseguire la copia di backup di un file di testo.
           La copia avviene tra un file sorgente, aperto in lettura, e un file di destinazione aperto in
           scrittura. Si esegue un’iterazione sul file sorgente leggendo una riga per volta che viene


                                                           1389
   1388   1389   1390   1391   1392   1393   1394   1395   1396   1397   1398