Documentos de Académico
Documentos de Profesional
Documentos de Cultura
import java.io.*;
import java.net.*;
import java.util.*;
/**
*
* @author Javier Pinto
*/
public class ManejoArchivos {
public static void main(String
arg) throws URISyntaxException
{
//File directorio = new File("C:\\Users\\javier
pinto\\Documents\\NetBeansProjects\\Achivos");
//File file = new File(directorio,"archivo.txt");
File("C:\\Users\\javier
pinto\\Documents\\NetBeansProjects\\Achivos","archivo.txt");
URI uri = new URI("file:///C:/Users/javier
pinto/Documents/NetBeansProjects/Achivos/archivo.txt");
File file = new File(uri);
if(!file.exists())
{
try{
file.createNewFile();
System.out.println(file.getName()+" Ha sido creado");
}catch(IOException ex){ex.printStackTrace();}
}else
{
try{
// FileWriter fw = new FileWriter(file,true);
// fw.append("Primera linea hola mundo");
// fw.append("Continuando segun texto");
// fw.close();
PrintWriter pw = new PrintWriter(file,"utf-8");
pw.println("Primera linea");
pw.println("Segunda linea");
pw.println(" ");
pw.printf("Hla mundo d/", 10);
pw.println(" ");
pw.printf("Hola %s en %d veces", "mundo", 100);
pw.close();
}catch(IOException ex){ex.printStackTrace();}
}
System.out.println("Nombre: "+file.getName());
System.out.println("Ruta Absoluta: "+file.getAbsolutePath());
System.out.println("Ruta: "+file.getPath());
System.out.println("Se Puede leer: "+file.canRead());
System.out.println("Se puede escribir: "+file.canWrite());
System.out.println("Se puede executar: "+file.canExecute());
System.out.println("Es Un directorio: "+file.isDirectory());
System.out.println("Ultima Modificacion: "+file.lastModified());
System.out.println("Tamaño: "+file.length());
}
}