package com.itheima1;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
//3.向list集合添加姓名{张三,李四,王五,二丫,钱六,孙七},将二丫替换为王小丫,写入到"D:\\stuinfo.txt"
public class Third_Array {
public static void main(String[] args) throws IOException {
ArrayList<String> list = new ArrayList<>();
list.add("张三");
list.add("李四");
list.add("王五");
list.add("二丫");
list.add("钱六");
list.add("孙七");
list.set(3, "王二丫");
FileOutputStream fos = new FileOutputStream("D:\\stuinfo.txt");
for (int i = 0; i < list.size(); i++) {
fos.write((list.get(i)+"\r\n").getBytes());
}
System.out.println("Done!");
fos.close();
}
}
|
|