如何扫描InputFile?

时间:2016-03-26 17:11:11

标签: java input output java.util.scanner

目前我有一个while循环,它读取一个简单命名为"输入"的输入文件。此输入文件包含数字,例如" 1 2 3 4"代表与我的问题无关的东西。要接收号码" 1",我使用scanner.nextInt();如果这是接收1的正确方法,我会坚持如何接收其他号码2 3 4.

while(scanner.hasNext()){

    int firstnum = scanner.nextInt();
    // How do I get the second, third, and fourth number?

    //It is not guaranteed that I will be given exactly 4 numbers, but I will be given at least that many.

1 个答案:

答案 0 :(得分:1)

只需继续循环并累积您遇到的数字,例如,列表:

instance.save(request.user)