Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. package menu_crear_leer_ficheros;
  2. import java.io.FileReader;
  3. import java.io.FileWriter;
  4. //import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.Scanner;
  7. public class Menu_Crear_Leer_Ficheros {
  8.  
  9. public static int menu(Scanner e) {
  10. int opcion=0;
  11. System.out.println("\t\t╔═════════════════════════════════╗");
  12. System.out.println("\t\t║ ║");
  13. System.out.println("\t\t║ TUS OPCIONES ║");
  14. System.out.println("\t\t║ ║");
  15. System.out.println("\t\t╚═════════════════════════════════╝");
  16. //System.out.println("\t\tNo tienes ninguna, tu vida es una mierda :)");
  17. System.out.println("\t\t┌───────────────────────────────────┐");
  18. System.out.println("\t\t│ │");
  19. System.out.println("\t\t│ 1. crear fichero frase │");
  20. System.out.println("\t\t│ 2. Visualizar fichero frase │");
  21. System.out.println("\t\t│ 3. Crear fichero vocales │");
  22. System.out.println("\t\t│ 4. Crear fichero consonantes │");
  23. System.out.println("\t\t│ 5. Visualizar fichero vocales │");
  24. System.out.println("\t\t│ 6. Visualizar fichero consonantes │");
  25. System.out.println("\t\t│ 7. Fin │");
  26. System.out.println("\t\t│ │");
  27. System.out.println("\t\t└───────────────────────────────────┘");
  28. do {
  29. System.out.print("\t\tTeclear opción (1-7): ");
  30. opcion = e.nextInt();
  31. }while(opcion <1 || opcion >7);
  32. return opcion;
  33. }
  34.  
  35. public static void main(String [] arg) {
  36. Scanner e = new Scanner(System.in);
  37. int opcion=0;
  38. do {
  39. opcion = menu(e);
  40. switch(opcion) {
  41. case 1:
  42. crearFicherofrase();
  43. break;
  44. case 2:
  45. visualizarFicherofrase();
  46. break;
  47. case 3:
  48. crearFicherovocales();
  49. break;
  50. case 4:
  51. crearFicheroconsonantes();
  52. break;
  53. case 5:
  54. visualizarFicherovocales();
  55. break;
  56. case 6:
  57. visualizarFicheroconsonantes();
  58. break;
  59. default:
  60. fin();
  61. }
  62. }while(opcion != 7);
  63. e.close();
  64. }
  65. static void crearFicherofrase() {
  66. int car = 0;
  67. try {
  68. FileWriter esc = new FileWriter("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
  69. car = (char)System.in.read();
  70. while(car!='*') {
  71. esc.write(car);
  72. car = (char)System.in.read();
  73. }
  74. esc.close();
  75. }catch(IOException ioe) {}
  76. System.out.println("Fichero creado.");
  77. }
  78. static void visualizarFicherofrase() {
  79. int car = ' ';
  80. String lintext = "";
  81. try {
  82. FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
  83. car = lec.read();
  84. while(car!=-1) {
  85. //System.out.print((char) car);
  86. lintext += (char) car;
  87. car = lec.read();
  88. }
  89. lec.close();
  90. }catch(IOException ioe) {}
  91. System.out.println("Contenido del fichero: ");
  92. System.out.println(lintext);
  93. System.out.println("\n\nFIN DE LA LECTURA\n");
  94. }
  95. static void crearFicherovocales() {
  96. int car = 0;
  97. char c = ' ', cm = ' ';
  98. try {
  99. FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
  100. FileWriter esc = new FileWriter("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textovocales.txt");
  101. car = lec.read();
  102. while(car!=-1) {
  103. c = (char)car;
  104. cm = Character.toLowerCase(c);
  105. if(cm=='a' || cm=='e' ||cm=='i' || cm=='o' || cm=='u') {
  106. if(car == 'a' || car == 'e' || car == 'i' || car == 'o' || car == 'u')
  107. esc.write(c);
  108. car=lec.read();
  109. }
  110. }
  111. lec.close();
  112. esc.close();
  113. }catch(IOException ioe) {}
  114. System.out.println("Fichero de vocales creado.");
  115. }
  116. static void crearFicheroconsonantes() {
  117. int car = 0;
  118. int c = ' ', cm = ' ';
  119. try {
  120. FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\texto.txt");
  121. FileWriter esc = new FileWriter("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textoconsonantes.txt");
  122. car = lec.read();
  123. while(car!=-1) {
  124. c = (char)car;
  125. cm = Character.toLowerCase(c);
  126. if(cm=='a' || cm=='e' ||cm=='i' || cm=='o' || cm=='u') {
  127. if(car != 'a' && car != 'e' && car != 'i' && car != 'o' && car != 'u')
  128. esc.write(c);
  129. car=lec.read();
  130. }
  131. }
  132. lec.close();
  133. esc.close();
  134. }catch(IOException ioe) {}
  135. System.out.println("Fichero de consonantes creado.");
  136. }
  137. static void visualizarFicherovocales() {
  138. int car = ' ';
  139. String lintext = "";
  140. try {
  141. FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textovocales.txt");
  142. car = lec.read();
  143. while(car!=-1) {
  144. //System.out.print((char) car);
  145. lintext += (char) car;
  146. car = lec.read();
  147. }
  148. lec.close();
  149. }catch(IOException ioe) {}
  150. System.out.println("Contenido del fichero: ");
  151. System.out.println(lintext);
  152. System.out.println("\n\nFIN DE LA LECTURA\n");
  153. }
  154. static void visualizarFicheroconsonantes() {
  155. int car = ' ';
  156. String lintext = "";
  157. try {
  158. FileReader lec = new FileReader("C:\\Users\\DAM-1-Exilio\\eclipse-workspace\\FicherosDatos\\textoconsonantes.txt");
  159. car = lec.read();
  160. while(car!=-1) {
  161. //System.out.print((char) car);
  162. lintext += (char) car;
  163. car = lec.read();
  164. }
  165. lec.close();
  166. }catch(IOException ioe) {}
  167. System.out.println("Contenido del fichero: ");
  168. System.out.println(lintext);
  169. System.out.println("\n\nFIN DE LA LECTURA\n");
  170. }
  171. static void fin() {
  172. System.out.print("\n\t\tFIN DEL PROGRAMA\n\t\t");
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement