import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class Rubrica { public static void main(String[] args) throws IOException { FileWriter fw = new FileWriter("rubrica.csv"); BufferedWriter bw = new BufferedWriter(fw); BufferedReader input = new BufferedReader(new InputStreamReader( System.in)); while (true) { System.out.println("Inserisci cognome (fine per terminare): "); String cognome = input.readLine(); if (cognome.equals("fine")) { break; } System.out.println("Inserisci nome: "); String nome = input.readLine(); System.out.println("Inserisci numero di telefono: "); String telefono = input.readLine(); String dato = cognome + ";" + nome + ";" + telefono; bw.write(dato); bw.newLine(); } bw.close(); System.out.println("Dati salvati"); } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class StampaRubrica { public static void main(String[] args) throws IOException { FileReader fr = new FileReader("rubrica.csv"); BufferedReader br = new BufferedReader(fr); System.out.println("CognometNometTelefono"); while (true) { String dato = br.readLine(); if (dato != null) { String[] d = dato.split(";"); System.out.println(d[0] + "t" + d[1] + "t" + d[2]); } else break; } br.close(); } }