Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 扫描仪无法正确读取输入_Java_Java.util.scanner - Fatal编程技术网

Java 扫描仪无法正确读取输入

Java 扫描仪无法正确读取输入,java,java.util.scanner,Java,Java.util.scanner,输出 File customer = new File("Cus.txt"); Scanner readCustomer = new Scanner(customer); while(readCustomer.hasNextLine()) { String line = readCustomer.nextLine(); String delims = ", "; String[] split = line.split(de

输出

 File customer = new File("Cus.txt");
    Scanner readCustomer = new Scanner(customer);
    while(readCustomer.hasNextLine())
    {
        String line = readCustomer.nextLine();
        String delims = ", ";
        String[] split = line.split(delims);
        int arr = Integer.parseInt(split[0]);
        int ser = Integer.parseInt(split[1]);
        int qui = Integer.parseInt(split[2]);
        int appt = Integer.parseInt(split[3]);
        int appL = Integer.parseInt(split[4]);
        Customer newCustomer = new Customer(arr, ser, qui, appt, appL);
        customerList.add(newCustomer);
        System.out.println("Customer arrival: " + newCustomer);
    }readCustomer.close();
CUS.TXT文件

912, 4, 922, 0, 0
915, 5, -1, 10, 10
918, 0, -1, 5, 5
920, 0, -1, 10, 10
925, 6, 930, 0, 0

我真是不知所措,不知道如何解决这个问题。是否有人看到任何错误,或者为什么无法读取我的拆分[4]?为什么要复制int-appt值中的内容?

@Jamie我无法理解您是如何获得输出的,因为您打印的是对象而不是值。我没有改变你的代码中的任何内容,它对我来说很好。你可能错过了一些很小的东西。使用下面的代码,您将能够获得所需的输出

915, 5, -1, 925, 10,  
918, 0, -1, 920, 5, 
920, 0, -1, 915, 10,  
925, 6, 930, -1, 0, 
Cus.txt文件

915, 5, -1, 925, 10, 
918, 0, -1, 920, 5, 
920, 0, -1, 915, 10, 
925, 6, 930, -1, 0, 

让我知道它是否有效。

我怀疑您的自定义构造函数中有一个错误,它解释了重复的
appL
。要么是that,要么是toString()方法。我将学习使用调试器来解决这个问题。请向我们展示客户构造函数的实现。如果您觉得这个(或任何)答案有帮助,请向上投票。如果这回答了您的问题,请将其标记为已接受的答案。谢谢
915, 5, -1, 925, 10, 
918, 0, -1, 920, 5, 
920, 0, -1, 915, 10, 
925, 6, 930, -1, 0, 
915, 5, -1, 925, 10,  
918, 0, -1, 920, 5, 
920, 0, -1, 915, 10,  
925, 6, 930, -1, 0,