我将我的excel文件导入Java。我现在正试图从我的数据中随机挑选 5 个人。我将如何去做...这是我到目前为止的代码。
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Rewards {
public static void main(String[] args) throws FileNotFoundException, IOException {
String fileName = "C:/Users/Jordan/Desktop/Project5.csv";
try {
BufferedReader br = new BufferedReader(new FileReader(fileName));
String strLine = null;
StringTokenizer st = null;
int lineNumber = 0, tokenNumber = 0;
while((fileName = br.readLine()) != null) {
lineNumber++;
String[] result = fileName.split(",");
for (int x=0; x<result.length; x++) {
System.out.println(result[x]);
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}