0
,以便後來我可以解析數組,如果該行包含3個雙打將其存儲到一個對象類型的數組?不幸的是,後來不得不將三雙打的行存儲到另一個數組中。如何將文本文件存儲到數組中?
這裏是到目前爲止我的代碼示例
public static void readFile(){
Scanner scnr = null;
File info = new File("info.txt");
try {
scnr = new Scanner(info);
} catch (FileNotFoundException e) {
System.out.println("file not found");
e.printStackTrace();
}
int counterLines = 0;
String nextLine = "";
while(scnr.hasNextLine()){
nextLine = scnr.nextLine();
counterLines ++;
}
System.out.println(counterLines);
String[] infoArray = new String[counterLines];
for(int i = 0; i < counterLines; i++){
infoArray[i] = scnr.nextLine();
System.out.println(infoArray[i]);