有人能幫助我輸入該數據爲3個對象在一個ArrayList(每個人)?讀取文本文件(文件選擇器),並存儲到一個ArrayList(每行的ArrayList
文本文件的例子:
Steve| Barkley| 258| 300
Carl |Johnson |142
Frank|Davidson
Java代碼:
//couldn't write the normal jfilechoose code above due to space
File playerFile = new File(selectedFile.getAbsolutePath());
Scanner in = new Scanner(playerFile);
String[] playerData; //array to hold data
while (in.hasNext()) {
String data = in.nextLine();
playertData = data.split("\\|");
playerData = Arrays.copyOf(playerData,playerData.length+1);
String firstName = playerData[0];
String lastName = playerData[1];
double playererayear1 = Double.parseDouble(playerData[2]==null?"0":playerData[2]);
double playererayear2 = Double.parseDouble(playerData[3]==null?"0":playerData[3]);
double playererayear3 = Double.parseDouble(playerData[4] == null?"0":playerData[4]);
是什麼studentdata這裏? – prasanth
啊我無意中把名字改成了學生,而我正在做testruns,但它仍然是playerData虐待試圖看看我是否可以編輯問題 – Alexa431
你想要一個'ArrayList