Académique Documents
Professionnel Documents
Culture Documents
2. Lectura:
BufferedReader in = new BufferedReader( new
FileReader("Datos.out"));
String cadena, cadena2 = new String();
while((cadena = in.readLine())!= null)
cadena2 += cadena + "\n";
in.close();
System.out.print(cadena2);
3. Ms interesante:
DataOutputStream salida = new
DataOutputStream(new
BufferedOutputStream(new
FileOutputStream("Datos.txt")));
salida.writeDouble(3.14159);
salida.writeBytes("Ese es PI\n");
salida.writeChars( "supercalifragilisticoespialidos\n");
salida.writeDouble(1.41413);
salida.writeUTF("Raz cuadrada de dos\n");
salida.close();
______________________________
Profesor: Magster Luis Gustavo Esquivel Quirs
luis.esquivel@ucr.ac.cr
4. Un poco ms complicado:
File ruta = new File("<<AQUI PONGA LA RUTA DE SU ESCRITORIO>> ");
File f = new File(ruta, "Datos.txt");
System.out.println(f.getAbsolutePath());
System.out.println(f.getParent());
System.out.println(ruta.getAbsolutePath());
System.out.println(ruta.getParent());
if (!f.exists()) {
System.out.println("Fichero " + f.getName() + " no existe");
if (!ruta.exists()) {
System.out.println("El directorio " + ruta.getName() + " no existe");
if (ruta.mkdir()) {
System.out.println("Directorio creado");
if (f.createNewFile()) {
System.out.println("Fichero " + f.getName() + " creado");
} else {
System.out.println("No se ha podido crear " + f.getName());
}
} else {
System.out.println("No se ha podido crear " + ruta.getName());
}
} else {
if (f.createNewFile()) {
System.out.println("Fichero " + f.getName() + " creado");
} else {
System.out.println("No se ha podido crear " + f.getName());
}
}
} else {
System.out.println("Fichero " + f.getName() + " existe");
System.out.println("Tamao " + f.length() + " bytes");
}
______________________________
Profesor: Magster Luis Gustavo Esquivel Quirs
luis.esquivel@ucr.ac.cr
______________________________
Profesor: Magster Luis Gustavo Esquivel Quirs
luis.esquivel@ucr.ac.cr