Advertisement
Grela

Ejercicio 3 no entra en bucle

Sep 22nd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.util.*;
  8.  
  9. public class Ejercicio3 {
  10.  
  11.     public static void main(String[] args) throws IOException {
  12.         Scanner sc = new Scanner(System.in);
  13.  
  14.         String objetivo = "nombres.txt";
  15.         FileWriter fichero = null;
  16.         PrintWriter pw = null;
  17.         File f = new File(objetivo);
  18.         fichero = new FileWriter(objetivo);
  19.         pw = new PrintWriter(fichero);
  20.         System.out.println("Introduce nombres, para con #");
  21.         escritura(sc, pw);
  22.  
  23.        
  24.         if (f.exists()) {
  25.             FileReader fr = new FileReader(f);
  26.             BufferedReader br = new BufferedReader(fr);
  27.             String name;
  28.             //name = br.readLine();
  29.             //System.out.println(name);// variable donde se recupera la informacion
  30.             while ((name = br.readLine()) != null) {
  31.                 System.out.println(5);
  32.  
  33.             }
  34.             System.out.println("\nLectura Finalizada");
  35.         }
  36.  
  37.         fichero.close();
  38.         pw.close();
  39.         sc.close();
  40.  
  41.     }
  42.  
  43.     private static void escritura(Scanner sc, PrintWriter pw) {
  44.         String nombre;
  45.         do {
  46.             nombre = sc.nextLine();
  47.             pw.println(nombre);
  48.         } while (!nombre.equals("#"));
  49.         System.out.println("\nEscritura finalizada");
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement