I'm trying to return the file selected by the user. That works fine. I can check fileToOpen in openFile and it is 100% correct, but when I sysout it in the main method I just get null. I want the path that the user has selected.
This is the main class:
public class Main {
public static void main(String[] args) {
File fileToOpen = null;
ReadIn openLog = new ReadIn();
openLog.openFile(fileToOpen);
System.out.println(fileToOpen);
}
}
This is the ReadIn class:
public class ReadIn extends JFrame{
public File openFile(File fileToOpen){
final JFileChooser fileChooser = new JFileChooser();
int modalToComponent=fileChooser.showOpenDialog(this);
if (modalToComponent == JFileChooser.APPROVE_OPTION) {
fileToOpen = fileChooser.getSelectedFile();
}
return fileToOpen;
}
}