![[JFileChooser.png|400]] It's easier to handle files if you can use standard dialogs to select them. The JFileChooser allows you to browse for documents. JFileChooser is quite easy to use, but there are two things to be aware of. Firstly, JFileChooser needs a parent frame to launch against (It can't be launched on its own). I've got round this here by making a JFrame that doesn't do anything else. Secondly, when the JFileChooser is launched, you use the showOpenDialog or showSaveDialog methods. These both return an integer saying, basically, whether OK or Cancel has been clicked. Note how, in the snippet below, you need to check if the OK button was clicked. ```java JFrame f = new JFrame(); JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showSaveDialog(f); File file; if (returnVal == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); try{ PrintWriter out = new PrintWriter(new FileWriter(file)); ...etc ``` # Extending JFileChooser... JFileChooser is a powerful tool. You can add filters, set defaults and more. ```java fc.setSelectedFile(new File("comparer.txt")); FileNameExtensionFilter filter = new FileNameExtensionFilter( ".txt and .comp files", "txt", "comp");   fc.setFileFilter(filter); ``` Try looking at the online help for more things you can do.