It seems fine but the the content is not write into file with write() method. I ask the user input with JoptionPane and add that data to ArrayList . The data is added , but when I try to output that data into file, it's not write to file.
public class fileArray {
public static void main(String[] args) throws IOException {
ArrayList al = new ArrayList();
File f =new File("notworking.txt");
String names = " ";
while(!names.isEmpty())
{
names=JOptionPane.showInputDialog("EnterName");
if(!names.isEmpty()){
al.add(names);}
}
FileWriter fw = new FileWriter(f.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
int sz= al.size();
for(int i =0;i<sz;i++){
bw.write((String) al.get(i));
System.out.println(al.get(i));
}
}
}