package zuoye;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
public class zuoye02 {
/**
*2:用带缓冲的字符流 读取名单.txt中 的内容(名单.txt已经给出), 在当中随机抽取20个人 打印在控制台.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("名单.txt"));
ArrayList<String> list = new ArrayList<>();
String b;
while((b=br.readLine())!=null){
list.add(b);
}
Collections.shuffle(list);
for (int i = 0; i < 20; i++) {
System.out.println(list.get(i));
}
}
}
|
|