save.addActionListener(new ActionListener() { // to save data to file @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File( "C:\\Users\\soFTech\\Desktop")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try { FileWriter fw = new FileWriter(chooser .getSelectedFile() + ".txt"); BufferedWriter out = new BufferedWriter(fw); for(int i = 0 ; i < accepted.size(); i++){ out.write(accepted.get(i)); out.newLine(); } for(int i = 0 ; i < rejected.size(); i++){ out.write(rejected.get(i)); out.newLine(); } out.close(); fw.close(); } catch (Exception ex) { ex.printStackTrace(); } } } });