我需要让我的程序读取一个文件,然后获取字符串中的数字并将它们排序为数组。我可以让我的程序读取文件并将其放到一个字符串中,但这就是我卡住的地方。所有数字都在文件的不同行上,但在字符串中显示为一个长整数。这是我到目前为止有:从文件中获取数字并对它们进行排序
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