I m trying to write ArrayList data in to the Text file using this code:
 public PrintWriter w() {
        try {
            FileWriter f = new FileWriter("C:\\Users\\jon\\Desktop\\a.txt");
            PrintWriter br = new PrintWriter(f);
            return br;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        return null;
    }
for (String g : a) {
  try {
    PrintWriter br = w();
    br.println(g);
    System.out.print(" " + g);
  } catch (Exception e1) {
    JOptionPane.showMessageDialog(null, e1);
  }
But it is not writing the data to the text file. Can anyone help me see the problem?