Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.*;
- public class Ejercicio3 {
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(System.in);
- String objetivo = "nombres.txt";
- FileWriter fichero = null;
- PrintWriter pw = null;
- File f = new File(objetivo);
- fichero = new FileWriter(objetivo);
- pw = new PrintWriter(fichero);
- System.out.println("Introduce nombres, para con #");
- escritura(sc, pw);
- if (f.exists()) {
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- String name;
- //name = br.readLine();
- //System.out.println(name);// variable donde se recupera la informacion
- while ((name = br.readLine()) != null) {
- System.out.println(5);
- }
- System.out.println("\nLectura Finalizada");
- }
- fichero.close();
- pw.close();
- sc.close();
- }
- private static void escritura(Scanner sc, PrintWriter pw) {
- String nombre;
- do {
- nombre = sc.nextLine();
- pw.println(nombre);
- } while (!nombre.equals("#"));
- System.out.println("\nEscritura finalizada");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement