如何把ArrayList集合寫入txt文件 謝謝!!!急用!!!
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
public class ArrayToTxt {
public static void main(String[] args) throws Exception{
File f=new File("d:/1.txt");
ArrayList<String> al=new ArrayList<String>();
al.add("first");
al.add("second");
al.add("third");
BufferedWriter bw=new BufferedWriter(new FileWriter(f));
for(int i=0;i<al.size();i++){
bw.write(al.get(i));
bw.newLine();
}
bw.close();
}
}