commit a860b6b94511c8ac9fceb3a3ebbcbde8023aeba5 Author: Cristobal Date: Mon Sep 19 17:50:33 2022 +0200 HolaFichero diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..09cf73a --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + HolaFichero + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/bin/com/cristobalbernal/es/HolaFichero.class b/bin/com/cristobalbernal/es/HolaFichero.class new file mode 100644 index 0000000..46811f7 Binary files /dev/null and b/bin/com/cristobalbernal/es/HolaFichero.class differ diff --git a/bin/module-info.class b/bin/module-info.class new file mode 100644 index 0000000..9b092ec Binary files /dev/null and b/bin/module-info.class differ diff --git a/src/com/cristobalbernal/es/HolaFichero.java b/src/com/cristobalbernal/es/HolaFichero.java new file mode 100644 index 0000000..a9e2378 --- /dev/null +++ b/src/com/cristobalbernal/es/HolaFichero.java @@ -0,0 +1,75 @@ +package com.cristobalbernal.es; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class HolaFichero { + static Scanner lector = new Scanner(System.in); + + public static void main(String[] args) throws IOException { + int opcion; + do { + opcion = menuPrincipal(); + switch (opcion){ + case 1: + CreoFicheroWindows(); + break; + case 2: + crearFicheroLinux(); + break; + } + + }while (opcion !=0); + } + + + public static void CreoFicheroWindows() throws IOException { + System.out.println("Creando fichero en Windows ..."); + File fwindows = new File("C:\\Users\\crist\\Documents\\2DAM\\BaseDeDatos\\BaseDaDatos.txt"); + + if(fwindows.createNewFile()) { + try (FileWriter escribir = new FileWriter(fwindows)) { + System.out.println("Creando fichero java!!!"); + escribir.write("Hola Jose"); + } + }else { + if(fwindows.exists()) { + System.out.println("Ya existe el archivo"); + }else { + System.out.println("No se ha creado el fichero!!!!"); + } + } + + } + public static void crearFicheroLinux() throws IOException { + + System.out.println("Creando fichero en linux!!!"); + File linux = new File("/home/mario/archivo.txt"); + + if(linux.createNewFile()) { + + try (FileWriter escribir = new FileWriter(linux)) { + System.out.println("Creando fichero java!!!"); + escribir.write("Hola Jose"); + + } + }else { + + System.out.println("No se ha creado el fichero!!!!"); + } + + } + public static int menuPrincipal() { + int opcion; + System.out.println("Escribe una opcion, dependera de tu sistema operativo:"); + System.out.println("1- Windows "); + System.out.println("2- Linux "); + System.out.println("Elige una opcion:"); + opcion = Integer.parseInt(lector.nextLine()); + return opcion; + + } +} + diff --git a/src/module-info.java b/src/module-info.java new file mode 100644 index 0000000..1206e39 --- /dev/null +++ b/src/module-info.java @@ -0,0 +1,3 @@ +module HolaFichero { + exports com.cristobalbernal.es; +} \ No newline at end of file