Java:File.createNewFile()
De W3API
Contenido |
[editar] Descripción
Método que crea un fichero vacío. Siempre y cuando el fichero no exista. Si el fichero es creado satisfactoriamente devuelve true, en caso de que el fichero exista devuelve false.
[editar] Sintaxis
public boolean createNewFile() throws IOException
[editar] Excepciones
[editar] Clases Java a las que aplica
[editar] Ejemplo
File fichero = new File("c:\\temp\\miFichero.txt");
try {
// A partir del objeto File creamos el fichero físicamente
if (fichero.createNewFile())
System.out.println("El fichero se ha creado correctamente");
else
System.out.println("No ha podido ser creado el fichero");
} catch (IOException ioe) {
ioe.printStackTrace();
}