我有一個簡單的Java問題,我需要一個簡單的答案,如果可能的話。我需要從文件輸入數據並將數據存儲到數組中。爲此,我必須讓程序打開數據文件,計算文件中元素的數量,關閉文件,初始化數組,重新打開文件並將數據加載到數組中。我主要是無法將文件數據存儲爲數組。下面是我有:基本文件讀取到陣列存儲
的讀取文件是在這裏:https://www.dropbox.com/s/0ylb3iloj9af7qz/scores.txt
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.text.*;
public class StandardizedScore8
{
//Accounting for a potential exception and exception subclasses
public static void main(String[] args) throws IOException
{
// TODO a LOT
String filename;
int i=0;
Scanner scan = new Scanner(System.in);
System.out.println("\nEnter the file name:");
filename=scan.nextLine();
File file = new File(filename);
//File file = new File ("scores.txt");
Scanner inputFile = new Scanner (file);
String [] fileArray = new String [filename];
//Scanner inFile = new Scanner (new File ("scores.txt"));
//User-input
// System.out.println("Reading from 'scores.txt'");
// System.out.println("\nEnter the file name:");
// filename=scan.nextLine();
//File-naming/retrieving
// File file = new File(filename);
// Scanner inputFile = new Scanner(file);
謝謝你的好榜樣! – Klinetel