Lettura file (orribile btw)

This commit is contained in:
La Programmatrice Verde
2025-11-18 08:51:59 +01:00
parent 4b1c4eb041
commit 6cc2432fa3

View File

@@ -4,8 +4,12 @@
*/
package rubricatelefonicafile;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;
/**
*
@@ -41,7 +45,7 @@ public class RubricaTelefonicaFile {
pausa();
break;
case 2:
aggiungiNumero();
// aggiungiNumero();
pausa();
break;
default:
@@ -49,8 +53,7 @@ public class RubricaTelefonicaFile {
pausa();
break;
}
}
catch (InputMismatchException _) {
} catch (InputMismatchException _) {
System.out.println("Errore: scelta non valida.");
pausa();
}
@@ -61,4 +64,38 @@ public class RubricaTelefonicaFile {
System.out.println("Premere un tasto per continuare. . .");
sc.nextLine();
}
static void cercaNumero() {
String nomeDaCercare;
String nome;
String telefono;
String s;
boolean b = true;
StringTokenizer st;
try {
FileReader f = new FileReader("src/rubricatelefonicafile/agenda.txt");
BufferedReader bf = new BufferedReader(f);
System.out.print("Inserire un nome: ");
nomeDaCercare = sc.nextLine();
s = bf.readLine();
while (s != null) {
st = new StringTokenizer(s, ";");
nome = st.nextToken();
telefono = st.nextToken();
s = bf.readLine();
System.out.println("Nome: " + nome + "\nTelefono: " + telefono);
}
f.close();
} catch (IOException _) {
System.out.println("Errore nella lettura del file.");
pausa();
}
}
}