BufferedReader bfr
= new BufferedReader(new FileReader("name.txt"));
ArrayList
<String> list
= new ArrayList<>();
while (true) {
String s
= bfr
.readLine();
if (s
== null
) {
break;
}
list
.add(s
);
}
bfr
.close();
Random random
= new Random();
int index
= random
.nextInt(list
.size());
String s
= list
.get(index
);
System
.out
.println(s
);
转载请注明原文地址: https://mac.8miu.com/read-493707.html