Folder management

2

I'm new to programming and I'm doing a project in which I want to create, open and delete folders, but I can not find how I can open it.

I use the library java.io.File . Try this:

public void crearCarpeta()                                                  //crea una carpeta(que va a guardar datos de una empresa en especifico)
{
    String direccion = null;
    String nombre = null;
    direccion = "C:\Users\MyZ\Desktop\respaldo programa java\Empresas";    //direccion de donde crea la carpeta
    nombre = textBoxNombreEmpresa.getText();                                //obtiene el nombre de la carpeta
    File carpeta = new File(direccion, nombre);
    carpeta.mkdir();  //creo la carpeta
    carpeta.
}

At the end where it puts folder. I thought I could put something like carpeta.open , but I can not find anything that I can open it with.

    
asked by Javier 23.11.2017 в 17:47
source

1 answer

2

For this purpose you could use the class Desktop (JDK 6 +) , which allows the application to start associated registered applications such as (open the browser, mail clients, folders) , before accessing the Open the current context instance must be obtained through the method. getDesktop ()

String direccion = null;
String nombre = null;
//direccion de donde crea la carpeta
direccion = "C:\Users\MyZ\Desktop\respaldo programa java\Empresas";    
nombre = textBoxNombreEmpresa.getText();   //obbtiene el nombre de la carpeta
File carpeta = new File(direccion, nombre);
carpeta.mkdir();  //creo la carpeta
Desktop.getDesktop().open(carpeta);

Another option would be (Windows environment) , execute the explorer.exe that is known in windows , adding the path getAbsolutePath

Runtime.getRuntime().exec("explorer " + carpeta.getAbsolutePath());
    
answered by 23.11.2017 в 18:24