0

I am building a desktop app using javafx. I need to download a file from FTP. I want before downloading the user should be prompted with the windows/mac explorer window to choose the download location. How can I achieve this in Javafx ??

I am downloading the file on the click of an button so I am using it inside my controller class.

user3649361
  • 944
  • 4
  • 20
  • 40

2 Answers2

1

You can choose a file with a FileChooser or choose a directory with a DirectoryChooser.

E.g.

DirectoryChooser dirChooser = new DirectoryChooser();
File chosenDir = dirChooser.showDialog(primaryStage);
James_D
  • 201,275
  • 16
  • 291
  • 322
  • I am using it on the click of a button, so I am using it inside my controller class in initialize method. How can I use it here because I don't have Stage variable there. – user3649361 Feb 09 '16 at 20:02
  • http://stackoverflow.com/questions/25491732/how-do-i-open-the-javafx-filechooser-from-a-controller-class' – James_D Feb 09 '16 at 20:09
0

Have you tried DirectoryChoser? It opens an OS native dialog to select a directory, and returns it as a File object. If you want to create a new file, you can read the Path of the selected directory, append a file name and create the new File object you want to save. For example:

    DirectoryChooser dirChooser = new DirectoryChooser();

    dirChooser.setTitle("Select a folder");

    File selectedDir = dirChooser.showDialog(primaryStage);

    String selectedDirPath = dirChooser.showDialog(mainApp.getPrimaryStage()).getAbsolutePath();

    File downloadedFile = new File(selectedDirPath + "/" + downloadedFileName);
Zach J
  • 81
  • 2
  • 6