Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public class Ficheros {
  2.  
  3. public static void main(String[] args) throws FileNotFoundException {
  4. Ficheros m = new Ficheros();
  5. Scanner sc = new Scanner(System.in);
  6. File file = new File("Prova.txt");
  7. m.introduir();
  8. int eleccio = sc.nextInt();
  9. while (eleccio != 4) {
  10. if (eleccio == 1) {
  11. m.fichero(file);
  12. }
  13. if (eleccio == 2) {
  14. m.lectura(file);
  15. }
  16. eleccio++;
  17. }
  18. }
  19.  
  20. public int introduir() {
  21. System.out.println("Elegir opcion");
  22. System.out.println("Verificar el fichero");
  23. System.out.println("Leer el fichero");
  24. return 0;
  25. }
  26.  
  27. public void fichero(File file) {
  28.  
  29. if (file.exists()) {
  30. System.out.println("Existe");
  31. } else {
  32. System.out.println("It doesn't");
  33. }
  34. }
  35.  
  36. public void lectura(File file) throws FileNotFoundException {
  37. Scanner entrada = new Scanner(file);
  38. System.out.println("");
  39. while (entrada.hasNextLine()) {
  40. System.out.println(entrada.nextLine());
  41.  
  42. }
  43. entrada.close();
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement