I created JFileChooser to open the file, but when I select the file and open it, the second time I want to select the file, JFileChooser is not in the current directory. How to install JFileChooser to open the current directory?
JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES ); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); int result = fileChooser.showOpenDialog( this ); if ( result == JFileChooser.APPROVE_OPTION ){ File fileName = fileChooser.getSelectedFile(); File path=fileChooser.getCurrentDirectory(); if ( ( fileName == null ) || ( fileName.getName().equals( "" ) ) ) { JOptionPane.showMessageDialog( this, "Invalid File Name", "Invalid File Name", JOptionPane.ERROR_MESSAGE ); } else{ currentPath=path.getPath()+"\\"+fileName.getName();} }
java file swing jfilechooser
Tofiq
source share