public class Demo_10 {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("张柏芝");
list.add("刘德华");
list.add("张亮");
list.add("张靓颖");
list.add("杨颖");
list.add("黄晓明");
System.out.println(list);
// 创建字符输入流对象
FileWriter writer = new FileWriter("D:\\a.txt");
BufferedWriter bw = new BufferedWriter(writer);
for (String thisstring : list) {
if (thisstring.startsWith("张")) {
bw.write(thisstring);
}
FileReader reader = new FileReader("D:\\a.txt");
BufferedReader br = new BufferedReader(reader);
String s = "";
if ((s = br.readLine()) != null) {
System.out.println(s);
}
}
bw.close();
}
}
|
|