0
private void populateEmployees() throws FileNotFoundException
    {
        File loc = new File(employeesPath);
        Scanner read = new Scanner(loc).useDelimiter(",");

        while (read.hasNext())
        {
            String firstName = read.next();
            String lastName = read.next();
            String age = read.next();
            String gender = read.next();
            String startDate = read.next();
            String currentEmployee = read.next();
            int totalHours = read.nextInt();
            String hourlyPay = read.nextLine();
            hourlyPay = hourlyPay.substring(1,hourlyPay.length() - 1);

            Employee employee = new Employee(firstName, lastName, age, gender, startDate, currentEmployee, totalHours, Double.parseDouble(hourlyPay));
            employees.add(employee);
        }

        read.close();
    }

While I did find a solution I'm still confused as to why String hourlyPay is getting a comma added to the beginning of its string. Anyone care to offer some insight on this?

javadev
  • 532
  • 3
  • 16
Arcsharp
  • 9
  • 2
  • Can you include the file you're reading? – Henry Twist Mar 08 '21 at 21:09
  • 2
    maybe similar to [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/q/13102045/15244370) - delimiter is not *consumed* by `nextInt()`, but not skipped by `nextLine()` - use `next()`, eventually followed by `nextLine()` to skip to next line if needed –  Mar 08 '21 at 21:27
  • but be aware that `next()` will read up to next comma (or end) including an eventual new line/carriage return character (and ignore the part in my previous comment about skipping to next line) better change delimiter to include end of line `\\n` –  Mar 08 '21 at 21:34

0 Answers0