public static void main(String[] args) throws IOException {
ArrayList<String> strList = new ArrayList<>();
strList.add("刘德华");
strList.add("张学友");
strList.add("刘亦菲");
strList.add("马德华");
BufferedWriter out = new BufferedWriter(new FileWriter("demo13.txt"));
//遍历集合
for(String s : strList){
out.write(s);
out.newLine();
}
//释放资源
out.close();
System.out.println("写入完毕!");
} |
|