1

I want to get the Name, Surname and birthdate out of a txt file this is what I have

Scanner scFile = new Scanner (new File("BirthDates.txt"));
        String Name;
        int BirthDates = 0;
        String Line = null;

            while(scFile.hasNext())
            {
                Line = scFile.nextLine();
                Scanner scLine = new Scanner(Line).useDelimiter("#");

                Name = scLine.next();
                BirthDates = scLine.nextInt();
                scLine.close();
                System.out.println(Name + BirthDates);
            }
        scFile.close();

The errors that I get The txt File

Nomade
  • 1,760
  • 2
  • 18
  • 33

1 Answers1

1

Problem source :

In this line : BirthDates = scLine.nextInt();, you try to get a birth day as int , but you read the second value after # like Jackson.

Solution :

Get the full name, then get your birth day :

  Name = scLine.next();
  secondeName = scLine.next();
  BirthDates = scLine.nextInt();

For more, see this

Community
  • 1
  • 1
Nomade
  • 1,760
  • 2
  • 18
  • 33