lundi 2 mars 2015

writing an arraylist to file



I'm having some trouble writing an array list to file using printwriter. I've tried another way that worked but it wouldn't print all the things from the array list just one. This is the way I'm trying at the moment and it won't print anything.



datArrayList = new ArrayList<theAccounts>();
File file = new File("output.txt");

public void writer() throws FileNotFoundException, IOException{


PrintWriter pw = new PrintWriter(new FileOutputStream(file));
FileOutputStream fo = new FileOutputStream(file);
int datList = datArrayList.size();

for (int i = 0; i < datList; i++){
pw.write(datArrayList.get(i).toString() + "\n");
}


Can anyone tell me what i should be doing to write all the items in the array to the output file? thank you :)




Aucun commentaire:

Enregistrer un commentaire