import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class Scrittura { public static void main(String[] args) { try { FileWriter fw = new FileWriter("dati.txt"); BufferedWriter bw = new BufferedWriter(fw); for (int i = 1; i <= 10; i++) { bw.write("3 x " + i + " = " + 3 * i); bw.newLine(); } bw.close(); } catch (IOException e) { System.out.println("Errore nel salvataggio dei dati"); } } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Lettura { public static void main(String[] args) { try { FileReader fr = new FileReader("dati.txt"); BufferedReader br = new BufferedReader(fr); for (int i = 1; i <= 10; i++) { System.out.println(br.readLine()); } br.close(); } catch (IOException e) { System.out.println("Errore nel salvataggio dei dati"); } } }