package test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
public class test {
public static void main(String[] args) {
//创建集合
List<String> list=new ArrayList<String>();
list.add("name");
list.add("臧三");
list.add("name");
list.add("李四");
list.add("name");
list.add("李四");
list.add("name");
list.add("李四");
try {
//将集合数据写入磁盘
FileWriter fw=new FileWriter("D:\\name.txt");
for(String s:list){
fw.write(s);
fw.write("\r\n");
}
fw.close();
//读取磁盘上文件数据
BufferedReader br = new BufferedReader(new FileReader("D:\\name.txt"));
String line;
//将读取到的数据写入到list集合中
List<String> list1=new ArrayList<String>();
while((line=br.readLine())!=null){
list1.add(line);
}
//循环输出list集合
for(int i=0;i<list1.size();i++){
System.out.println(list1.get(i));
}
br.close();
} catch (Exception e) {
}
}
}