Problem with creating files and files in JAVA (After creating installer) [closed]

1

Well, the problem is as follows.   When programming with neatbeans and running the program everything works fine ... I create a folder and a .txt file as it should be, but, after creating the application installer and installing it (in C :) I do not create any folder or txt file.  I do not know if the problem is because you have to give some administrative permissions or something in the code so you can create the files, etc.  I am a novice in programming and any comments I thank you in advance.
  - The address is correct -
In theory if the folder does not exist it would create it Here the code:

public class respaldo {
    JFileChooser selector = new JFileChooser(System.getProperty("user.dir"));
    String user="root";
    String pass="";
    String password="";
    String host ="localhost";
    String bd="veterinaria";
    String path="C:/xampp/mysql/bin/mysqldump.exe";
    String backup="mysqldump --user="+user+" --password="+password+" -v "+bd+" > "+path;
    private String extension=".sql";
    Runtime rt = Runtime.getRuntime();
    String dir;
    correo c = new correo();
    String nombrearchivo ;
    
    
    public void respaldar(){
      Date fecha = new Date();
         SimpleDateFormat formateador = new SimpleDateFormat("dd-MM-yyyy");   
          dir=""+selector.getCurrentDirectory();
        try {    
               File fl=new File(dir);
               File fl2= new File(dir,"respaldos");
               fl2.mkdir(); 
               File file=new File(fl2,formateador.format(fecha));
               nombrearchivo = file.getName();
               path=file.getAbsolutePath()+extension;       
               JOptionPane.showMessageDialog(null,path);
                    String command = "C:/xampp/mysql/bin/mysqldump --user="+user+" --password="+pass+" "+bd+" -r"+path;
                 rt.exec(command);
                
        } catch (IOException ex) {
            Logger.getLogger(respaldo.class.getName()).log(Level.SEVERE, null, ex);
            
        }
    }
    
asked by Palazzus 0 04.01.2018 в 03:52
source

1 answer

1

The problem you suffer is because you are not escaping the route you provide to parameter -r (result file) of mysqldump . That causes it to be divided into several different parameters, causing unexpected operation.

Execution generated:

mysqldump -u usuario -pclave bbdd -r C:\Program Files (86)\...

It is likely that at the root of C: you have created a file called Program that contains the export ( C:\Program ). The rest of the route is interpreted as the names of tables to be exported :

mysqldump [options] db_name [tbl_name ...]

To allow Java to decide the most appropriate way to escape the parameters according to the operating system that is being used, you have to use the call Runtime.exec(String[]) :

rt.exec(new String[] {
    "C:/xampp/mysql/bin/mysqldump",
    "-u", user,
    "-p" + pass,
    bd,
    "-r",
    path
});
    
answered by 08.01.2018 в 12:48