Browse Source

Actualizar 'src/yaros/HolaFichero/HolaFichero.java'

master
Yaroslav 1 year ago
parent
commit
2b2af60d7f
1 changed files with 50 additions and 50 deletions
  1. +50
    -50
      src/yaros/HolaFichero/HolaFichero.java

+ 50
- 50
src/yaros/HolaFichero/HolaFichero.java View File

@ -3,58 +3,58 @@ package yaros.HolaFichero;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
public class HolaFichero { public class HolaFichero {
static char Sistema;
public static void main(String args[]) {
char Sistema=MiSistema();
System.out.println(Sistema);
}
static char MiSistema() {
char Sis='?';
char Windows='W';
char Linux='L';
System.out.println("Creando mi primer fichero ...");
String so = System.getProperty("os.name");
System.out.print("El sistema operativo es: ");
if (so.charAt(0)==Windows) {
System.out.print("Windows -> ");
Sis=Windows;
try {
new HolaFichero().CreoFicheroWindows();
}catch(IOException e) {
System.out.print("Error");
}
public static void main(String args[]) {
MiSistema();
} }
else {
System.out.print("Linux -> ");
Sis=Linux;
try {
new HolaFichero().CreoFicheroLinux();
}catch(IOException e) {
System.out.print("Error");
}
static boolean MiSistema() {
char Windows='W';
char Linux='L';
System.out.println("Creando mi primer fichero ...");
String os = System.getProperty("os.name");
System.out.print("El sistema operativo es: ");
if (os.charAt(0)==Windows) {
System.out.print("Windows. ");
new HolaFichero().CreoFicheroWindows();
return true;
}
if (os.charAt(0)==Linux) {
System.out.print("Linux:");
new HolaFichero().CreoFicheroLinux();
return true;
}
return false;
} }
return Sis;
}
public void CreoFicheroWindows() throws IOException {
System.out.println("Creando fichero en Windows ...");
File fwindows = new File("C:\\Users\\yaros\\Documents\\Otros\\CreoFicheroWindows.txt");
if (!fwindows.exists()) {
fwindows.createNewFile();
public void CreoFicheroWindows(){
System.out.println("Creando fichero en Windows");
File ficheroW = new File("C:\\Users\\yaros\\Documents\\Otros\\CreoFicheroWindows.txt");
if (!ficheroW.exists()) {
try {
ficheroW.createNewFile();
} catch (IOException e) {
System.out.print("Error");
}
System.out.println("Fichero creado");
} }
System.out.println("Fichero creado en Windows.");
}
public void CreoFicheroLinux() throws IOException {
System.out.println("Creando fichero en Linux ...");
File funix = new File("/home/..../CreoFicheroUnix.txt");
if (!funix.exists()) {
funix.createNewFile();
else{
System.out.println("Fichero ya existe");
} }
System.out.println("Fichero creado en Unix.");
}
}
public void CreoFicheroLinux() {
System.out.println("Creando fichero en Linux");
File ficheroL = new File("/home/Yaros/Documents/CreoFicheroUnix.txt");
if (!ficheroL.exists()) {
try {
ficheroL.createNewFile();
} catch (IOException e) {
System.out.print("Error");
}
System.out.println("Fichero creado");
} else {
System.out.println("Fichero ya existe");
}
}
} }

Loading…
Cancel
Save