Well first post since a long time. Anyways I need help with, how do I create an ArrayList that saves every element to a file?
I have created an ArrayList and it is functional, however how do I make it save the elements to a file?
Anyone that could provide some tips and help for me?
Thanks in advance guys !
Um I haven't tried this but try:
Code:PrintWriter fout = new PrintWriter(new FileWriter("OUT.txt")); for (int index=0;index<arlNums.size();index++) { fout.println(arlNums.get(index)); }
Yeah just tried it, and it's working great.
That does work. Hope it helps.Code:import java.util.*; import java.io.*; public class al { public static void main(String[] args) throws IOException { Scanner fin = new Scanner(new FileReader("data.txt")); PrintWriter fout = new PrintWriter(new FileWriter("OUT.txt")); ArrayList alnNums = new ArrayList<Integer>(); while (fin.hasNextInt()) { alnNums.add(fin.nextInt()); } for (int index=0;index<alnNums.size();index++) { fout.println(alnNums.get(index)); } fout.close(); fin.close(); } }![]()
Yep works and thanks![]()
Thank you for the info~
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks