我需要讓我的程序讀取一個文件,然後獲取字符串中的數字並將它們排序爲數組。我可以讓我的程序讀取文件並將其放到一個字符串中,但這就是我卡住的地方。所有數字都在文件的不同行上,但在字符串中顯示爲一個長整數。這是我到目前爲止有:從文件中獲取數字並對它們進行排序
public static void main(String[] args) {
String ipt1;
Scanner fileInput;
File inFile = new File("input1.dat");
try {
fileInput = new Scanner(inFile);
//Reads file contents
while (fileInput.hasNext()) {
ipt1 = fileInput.next();
System.out.print(ipt1);
}
fileInput.close();
}
catch (FileNotFoundException e) {
System.out.println(e);
}
}
那麼什麼是你的問題? – Idris
@Srink我如何讀取文件並將每行放入數組元素中? – user2848462