0

I have the following code

 Process p = new ProcessBuilder("D:\\Encryption.exe", "D:\\Cat-hd-
 wallpapers_remain_both2.jpg").start();

This code can run fine but instead of declaring "D:\Cat-hd- wallpapers_remain_both2.jpg" this in my code I want to use file chooser for selecting file. I use the following code but still not working.

 imageUpload.setOnMouseClicked(event -> {
        FileChooser fileChooser=new FileChooser();
        fileChooser.setInitialDirectory(new File("c:\\"));
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("JPG Images","*.jpg"),
                new FileChooser.ExtensionFilter("JPEG Images","*.jpeg"),
                new FileChooser.ExtensionFilter("PNG Images","*.png"));
        File file=fileChooser.showOpenDialog(null);

        if (file!=null){
            try {
                imageUpload.setImage(new Image(file.toURI().toURL().toString()));
                Process p = new ProcessBuilder("D:\\Encryption.exe",file.getAbsoluteFile().getAbsolutePath()).start();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException ex) {
                Logger.getLogger(decriptImageController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

it throws the following error

CreateProcess error=2, The system cannot find the file specified

Can you please help me to find out the problem.Thanks in advanced.

Sony
  • 55
  • 1
  • 5

1 Answers1

0

The error "CreateProcess error=2, The system cannot find the file specified" refers to the executable, i.e. Encryption.exe, and has nothing to do with the JPEG file argument passed to it.

There must be something about your 2nd example that is different, but not shown in your question. Perhaps a subtle typo, e.g. Encyrption.exe etc...

Adam
  • 35,919
  • 9
  • 100
  • 137
  • Thank you @Adam I just fix it but my question is how can I use file chooser instead of mentioning the file name in the process builder.Thanks in advanced. – Sony May 07 '17 at 15:40