Postgresql database backup from java

0

In the view I have a text field in which I indicate the address where I will save the file next to the name that I want to place it.

String direccion = vista.txtFileRespaldar.getText();

This is converted to type file in the following way:

File dir= new File (direccion);

I check if the address is valid and proceed to the backup of the db:

if(direccion.isEmpty()){
    JOptionPane.showMessageDialog(vista, "Debe indicar una ruta", "Error", JOptionPane.ERROR_MESSAGE);
}else if(dir.exists()){
    boolean hecho=modelo.BD_backup(direccion);
    if(hecho){
        System.out.println("terminado backup " + dir);
    }else{
        JOptionPane.showMessageDialog(vista, "Error al intentar realizar el backup", "Error", JOptionPane.ERROR_MESSAGE);
    }
}else{
    System.out.println("error en backup" + dir);
    JOptionPane.showMessageDialog(vista, "Debe indicar una ruta valida", "Error", JOptionPane.ERROR_MESSAGE);
}

I indicate any route on my PC and it tells me that the route is not valid, that is, the last else .

Try indicating the path and name of a .backup file already created and backing it correctly.

Some idea of why?

    
asked by Pablo Contreras 27.08.2017 в 00:27
source

1 answer

2

When you create the directory

File dir= new File (direccion);

Create the instance, but you need to create the physical directories

dir.mkdir();

or

dir.mkdirs();

depending on the case you require and if you want to create a file you should use

File file = new File(nombreArchivo);
file.createNewFile();

source link

    
answered by 27.08.2017 / 01:38
source