package com.companyname.common.test; import java.io.*; import java.util.ArrayList; import java.util.Random; /** * @Description * @Author Created by shusheng. * @Email [email protected] * @Date 2018/12/8 */ public class GetName { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("a.txt")); ArrayList<String> array = new ArrayList<String>(); String line = null; while((line=br.readLine())!=null){ array.add(line); } Random r = new Random(); int index = r.nextInt(array.size()); String name = array.get(index); System.out.println("幸运者是:"+name); } }
原文地址:https://www.cnblogs.com/zuixinxian/p/10086995.html
时间: 2024-11-05 20:48:48