diff --git a/bin/com/antonioFrische/MiCat.class b/bin/com/antonioFrische/MiCat.class index 2579e89..b6c5d57 100644 Binary files a/bin/com/antonioFrische/MiCat.class and b/bin/com/antonioFrische/MiCat.class differ diff --git a/src/com/antonioFrische/MiCat.java b/src/com/antonioFrische/MiCat.java index ee73b4a..926190b 100644 --- a/src/com/antonioFrische/MiCat.java +++ b/src/com/antonioFrische/MiCat.java @@ -1,7 +1,71 @@ package com.antonioFrische; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; public class MiCat { + public static final String PATH = "C:\\Users\\AntonioFrische\\OneDrive - ABACCO Solutions\\Documents\\Schule_22_23_CFGS\\Acceso_Datos\\SpringTool_4\\contents\\sts-4.16.0.RELEASE\\Archnew.txt"; + public static void main(String[] args) { + File archivo = new File(PATH); + try{ + if(archivo.exists()) { + FileWriter fw = new FileWriter(archivo, true); + writeTo(fw); + + fw.flush(); + fw.close(); + } else { + FileWriter fw=new FileWriter(archivo); + writeTo(fw); + + fw.flush(); + fw.close(); + } + FileReader frResultado = new FileReader(PATH); + BufferedReader brResultado = new BufferedReader(frResultado); + + System.out.println("Contenido del fichero:"); + System.out.println(brResultado.readLine()); + + frResultado.close(); + brResultado.close(); + }catch(IOException e){ + System.out.println("Error IOException: "+e); + } + + + } + + public static void writeTo(FileWriter fileWriter) throws IOException { + Scanner reader = new Scanner(System.in); + + boolean stop = false; + String introduction; + String slash = "\\"; + + do { + System.out.println("escribe linia por lina(itiliza el slash para parar):"); + introduction = reader.nextLine(); + try { + for(int i = 0; i < introduction.length(); i++) { + if(introduction.charAt(i) == slash.charAt(0)) { + stop = true; + break; + + } else { + fileWriter.write(introduction.charAt(i)); + } + System.out.print(introduction.charAt(i)); + } + System.out.print("\n"); + } catch(NullPointerException npe) { + } + } while(stop == false); } }