//Aplicatie Java cu fluxuri de intrare si iesire //program care citeste numere de la tastatura si le memoreaza intr-un fisier iesire.txt //apoi,folosind clasa StreamTokenizer parsam datele si le afisam la terminal import java.io.*; import java.lang.*; public class Aplicatie1 { private BufferedReader tastatura; public static void main (String[] args) { Aplicatie1 a=new Aplicatie1(); a.executa(); a.executa1(); } public void executa() { try { //declaram 2 fisiere si un buffer pt tastatura FileWriter f1=new FileWriter("iesire.txt"); //crearea unui flux de intrare dintr-un fisier care va fi parsat de un StreamTokenizer String vid=" "; tastatura=new BufferedReader(new InputStreamReader(System.in),1); for (int i=1;i<10;i++) { System.out.println("dati un numar:"); String sir=tastatura.readLine(); f1.write(sir); f1.write(vid); // f1.write(Integer.valueOf(sir)); //goleste bufferul de iesire in fisier // String linie=tastatura.readLine(); } f1.close(); } catch(IOException e) { System.out.println("eroare"); }
} public void executa1() { try{ StreamTokenizer p=new StreamTokenizer(new FileReader("iesire.txt")); p.eolIsSignificant(false); while(p.nextToken()!=p.TT_EOF) if (p.ttype==p.TT_NUMBER) System.out.println("numar:"+p.nval);}catch(IOException e){ System.out.println("eroare"); } } }