Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ficheros {
- public static void main(String[] args) throws FileNotFoundException {
- Ficheros m = new Ficheros();
- Scanner sc = new Scanner(System.in);
- File file = new File("Prova.txt");
- m.introduir();
- int eleccio = sc.nextInt();
- while (eleccio != 4) {
- if (eleccio == 1) {
- m.fichero(file);
- }
- if (eleccio == 2) {
- m.lectura(file);
- }
- eleccio++;
- }
- }
- public int introduir() {
- System.out.println("Elegir opcion");
- System.out.println("Verificar el fichero");
- System.out.println("Leer el fichero");
- return 0;
- }
- public void fichero(File file) {
- if (file.exists()) {
- System.out.println("Existe");
- } else {
- System.out.println("It doesn't");
- }
- }
- public void lectura(File file) throws FileNotFoundException {
- Scanner entrada = new Scanner(file);
- System.out.println("");
- while (entrada.hasNextLine()) {
- System.out.println(entrada.nextLine());
- }
- entrada.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement