title: JavaFX Filechooser: Save Image to Resources and save Path to Database
body: <p>i want to save a selected image which i get with the FileChooser into my Resource folder within the existing project. After this, i want to save the path into my database. </p>
  
  <p>I use JavaFX for this and put the whole code within the "Submit Button" action. Now the code takes the path of the selected image and creates a new image. How can i save this image now to my directory and how do i get the path to this? </p>
  
  <pre><code>@FXML
  public void pathButtonClicked(ActionEvent actionEvent) {
  
      LOG.info("Image Path button clicked");
  
      FileChooser chooser = new FileChooser();
      chooser.setTitle("Select Image File");
  
      chooser.getExtensionFilters().addAll(
          new FileChooser.ExtensionFilter("Image Files",
              "*.png", "*.jpg", "*.jpeg"));
  
      File file = chooser.showOpenDialog(null);
  
  if(file != null){
          LOG.info("Got file " + file);
         // String filePath = file.getAbsolutePath().toString();
  
              try {
                  String imagePath = file.toURI().toURL().toString();
                  Image image = new Image(imagePath, 500,500,true,true,true);
                  LOG.info("Image created " + image);
  
              } catch (MalformedURLException e) {
                  e.printStackTrace();
              }
  
          }else{
          LOG.info("File not found!");
          Alert alert = new Alert(Alert.AlertType.INFORMATION);
          alert.setTitle("Information Dialog");
          alert.setHeaderText("Please Select a File");
          alert.showAndWait();
      }
  </code></pre>