There are two ways to do this, depending on what you want.
If you want to separate all input into a colon, you can use the method useDelimiter(), as others have pointed out:
scanner.useDelimiter(":");
while (scanner.hasNext())
{
String token = scanner.next();
}
If you want to separate each line with a colon, then it would be much easier to use the method String split():
while (scanner.hasNextLine())
{
String[] parts = scanner.nextLine().split(":");
// The parts array now contains ["something", "somethingelse"]
}
source
share