For java programming, what is the difference between read() and next()?

For example:

Let's say I import the java Scanner class.
Then I proceed as follows:

Scanner userInput = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int numberOfStudents = userInput.nextInt();
System.out.println("The number of students you entered is: " + numberOfStudents);

My question is would this work if I replaced "int numberOfStudents = userInput.nextInt()" with "int numberOfStudents = userInput.readInt()"? What is the difference between next and read? When should one be used over the other?

You should look at the code of the nextInt() and readInt() methods in the Scanner class to determine how they differ in functionality.

Or, paste the Scanner class here so that we can take a look.