@ Cmd public File chooseFile ( final String fileKey ) { log . debug ( "Opening file chooser dialog" ) ; JFileChooser fileChooser = new JFileChooser ( System . getProperty ( JFunkConstants . USER_DIR ) ) ; fileChooser . setFileSelectionMode ( JFileChooser . FILES_AND_DIRECTORIES ) ; fileChooser . setPreferredSize ( new Dimension ( 600 , 326 ) ) ; int fileChooserResult = fileChooser . showOpenDialog ( null ) ; if ( fileChooserResult == JFileChooser . APPROVE_OPTION ) { File file = fileChooser . getSelectedFile ( ) ; String filename = file . toString ( ) ; log . info ( "Assigning file path '{}' to property '{}'" , filename , fileKey ) ; config . put ( fileKey , filename ) ; return file ; } log . error ( "No file or directory was chosen, execution will abort" ) ; throw new IllegalArgumentException ( "No file or directory was chosen" ) ; }
Opens a file chooser dialog which can then be used to choose a file or directory and assign the path of the chosen object to a variable . The name of the variable must be passed as a parameter .