I'm able to create a csv file. But i stuck at the part of rewriting the csv file.

Here's my code :
This code here allow me to select a directory and save the .csv I want to be in.
Java Code:
 private void SaveFingerprintActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JFileChooser chooser = new JFileChooser();
        
        chooser.setCurrentDirectory(new File("."));
        chooser.setDialogTitle("Select a directory to save");
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("CSV file", "csv"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
        {
            String newFile = chooser.getSelectedFile().getAbsolutePath();
            if (!newFile.endsWith(".csv"))
            {
                newFile += ".csv";
            }
            File f = new File(newFile);
            if (f.exists())
            {
                int selection = JOptionPane.showConfirmDialog(null, "File exists. Overwrite file?", "File exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                if (selection == JOptionPane.YES_OPTION)
                {
                    SaveDescriptorTypes(newFile);
                }
            }
            else
            {
                SaveDescriptorTypes(newFile);
            }
            try {
                generateCsvFile(newFile);
            } catch (IOException ex) {
                Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                generateCsvFile(newFile);
            } catch (IOException ex) {
                Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

private void generateCsvFile(String newFile) throws IOException {
            
        FileWriter writer = new FileWriter(newFile);
}
And here's the code:
When I press the convert button, the thing I want to convert will appear in the .csv file
Java Code:
 BufferedReader br = null;
         
        try {
            FileWriter writer = null;
            try {
                writer = new FileWriter(selectedFile);
            } catch (IOException ex) {
                Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            br = new BufferedReader(new FileReader(selectedFile));
            IteratingSMILESReader iteratingSMILESReader = new IteratingSMILESReader(br, DefaultChemObjectBuilder.getInstance());
            if (iteratingSMILESReader.hasNext()) {
                IAtomContainer molecule = (IAtomContainer)iteratingSMILESReader.next();

                int maxFingerprints = 1024;
                String[] descriptorValues_ = new String[maxFingerprints];
                for (int i=0; i<maxFingerprints; ++i) {
                    descriptorValues_[i] = "";
                }

                BitSet fingerprint = new Fingerprinter().getFingerprint(molecule);
                String one = Integer.toString(1);
                String zero = Integer.toString(0);
                for (int i=0; i<maxFingerprints; ++i) {
                    if (fingerprint.get(i)==true) {
                        try {
                            writer.append(one);
                        } catch (IOException ex) {
                            Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        try {
                            writer.append(",");
                        } catch (IOException ex) {
                            Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    } else if (fingerprint.get(i)==false) {
                        try {
                            writer.append(zero);
                        } catch (IOException ex) {
                            Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        try {
                            writer.append(",");
                        } catch (IOException ex) {
                            Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
           }

        } catch (CDKException ex) {
            Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(FYP_CDKView.class.getName()).log(Level.SEVERE, null, ex);
            }
            

        }
How can I improve my program so that when the convert button is press the thing i want to convert will appear in my saved .csv file ?