Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package menu_crear_leer_ficheros;
- import java.io.FileReader;
- import java.io.FileWriter;
- //import java.io.FileReader;
- import java.io.IOException;
- import java.util.Scanner;
- public class Menu_Crear_Leer_Ficheros {
- public static int menu(Scanner e) {
- int opcion=0;
- System.out.println("\t\t╔═════════════════════════════════╗");
- System.out.println("\t\t║ ║");
- System.out.println("\t\t║ TUS OPCIONES ║");
- System.out.println("\t\t║ ║");
- System.out.println("\t\t╚═════════════════════════════════╝");
- //System.out.println("\t\tNo tienes ninguna, tu vida es una mierda :)");
- System.out.println("\t\t┌───────────────────────────────────┐");
- System.out.println("\t\t│ │");
- System.out.println("\t\t│ 1. crear fichero frase │");
- System.out.println("\t\t│ 2. Visualizar fichero frase │");
- System.out.println("\t\t│ 3. Crear fichero vocales │");
- System.out.println("\t\t│ 4. Crear fichero consonantes │");
- System.out.println("\t\t│ 5. Visualizar fichero vocales │");
- System.out.println("\t\t│ 6. Visualizar fichero consonantes │");
- System.out.println("\t\t│ 7. Fin │");
- System.out.println("\t\t│ │");
- System.out.println("\t\t└───────────────────────────────────┘");
- do {
- System.out.print("\t\tTeclear opción (1-7): ");
- opcion = e.nextInt();
- }while(opcion <1 || opcion >7);
- return opcion;
- }
- public static void main(String [] arg) {
- Scanner e = new Scanner(System.in);
- int opcion=0;
- do {
- opcion = menu(e);
- switch(opcion) {
- case 1:
- crearFicherofrase();
- break;
- case 2:
- visualizarFicherofrase();
- break;
- case 3:
- crearFicherovocales();
- break;
- case 4:
- crearFicheroconsonantes();
- break;
- case 5:
- visualizarFicherovocales();
- break;
- case 6:
- visualizarFicheroconsonantes();
- break;
- default:
- fin();
- }
- }while(opcion != 7);
- e.close();
- }
- static void crearFicherofrase() {
- int car = 0;
- try {
- FileWriter esc = new FileWriter("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
- car = (char)System.in.read();
- while(car!='*') {
- esc.write(car);
- car = (char)System.in.read();
- }
- esc.close();
- }catch(IOException ioe) {}
- System.out.println("Fichero creado.");
- }
- static void visualizarFicherofrase() {
- int car = ' ';
- String lintext = "";
- try {
- FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
- car = lec.read();
- while(car!=-1) {
- //System.out.print((char) car);
- lintext += (char) car;
- car = lec.read();
- }
- lec.close();
- }catch(IOException ioe) {}
- System.out.println("Contenido del fichero: ");
- System.out.println(lintext);
- System.out.println("\n\nFIN DE LA LECTURA\n");
- }
- static void crearFicherovocales() {
- int car = 0;
- char c = ' ', cm = ' ';
- try {
- FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
- FileWriter esc = new FileWriter("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textovocales.txt");
- car = lec.read();
- while(car!=-1) {
- c = (char)car;
- cm = Character.toLowerCase(c);
- if(cm=='a' || cm=='e' ||cm=='i' || cm=='o' || cm=='u') {
- if(car == 'a' || car == 'e' || car == 'i' || car == 'o' || car == 'u')
- esc.write(c);
- car=lec.read();
- }
- }
- lec.close();
- esc.close();
- }catch(IOException ioe) {}
- System.out.println("Fichero de vocales creado.");
- }
- static void crearFicheroconsonantes() {
- int car = 0;
- int c = ' ', cm = ' ';
- try {
- FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
- FileWriter esc = new FileWriter("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textoconsonantes.txt");
- car = lec.read();
- while(car!=-1) {
- c = (char)car;
- cm = Character.toLowerCase(c);
- if(cm=='a' || cm=='e' ||cm=='i' || cm=='o' || cm=='u') {
- if(car != 'a' && car != 'e' && car != 'i' && car != 'o' && car != 'u')
- esc.write(c);
- car=lec.read();
- }
- }
- lec.close();
- esc.close();
- }catch(IOException ioe) {}
- System.out.println("Fichero de consonantes creado.");
- }
- static void visualizarFicherovocales() {
- int car = ' ';
- String lintext = "";
- try {
- FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textovocales.txt");
- car = lec.read();
- while(car!=-1) {
- //System.out.print((char) car);
- lintext += (char) car;
- car = lec.read();
- }
- lec.close();
- }catch(IOException ioe) {}
- System.out.println("Contenido del fichero: ");
- System.out.println(lintext);
- System.out.println("\n\nFIN DE LA LECTURA\n");
- }
- static void visualizarFicheroconsonantes() {
- int car = ' ';
- String lintext = "";
- try {
- FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textoconsonantes.txt");
- car = lec.read();
- while(car!=-1) {
- //System.out.print((char) car);
- lintext += (char) car;
- car = lec.read();
- }
- lec.close();
- }catch(IOException ioe) {}
- System.out.println("Contenido del fichero: ");
- System.out.println(lintext);
- System.out.println("\n\nFIN DE LA LECTURA\n");
- }
- static void fin() {
- System.out.print("\n\t\tFIN DEL PROGRAMA\n\t\t");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement