import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class ArrayListToTxtDemo2 { public static void main(String[] args) throws IOException { ArrayListarray = new ArrayList (); Student s1 = new Student("19031235", "郭靖", 22, "西安"); Student s2 = new Student("19031236", "黄蓉", 22, "西安"); Student s3 = new Student("19031237", "张三丰", 22, "西安"); Student s4 = new Student("19031238", "谢逊", 22, "西安"); array.add(s1); array.add(s2); array.add(s3); array.add(s4); BufferedWriter bw = new BufferedWriter(new FileWriter("D:\Java\java作业\myCharStream\abc.txt")); for (Student s : array) { StringBuilder sb = new StringBuilder(); sb.append(s.getSid()).append(",").append(s.getName()).append(",").append(s.getAge()).append(",").append(s.getAddress()); bw.write(sb.toString()); bw.newline(); bw.flush(); } bw.close(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)