Wednesday 31 December 2014

A Scanner quickie

Sometimes I want to read a smallish text file in one gulp without going through all the input stream chaining or using external libraries. This can be done with the Scanner class when the delimiter is set to EOF:

try (Scanner scanner = new Scanner(file).useDelimiter("\\Z")) {
    fileContent= scanner.next();
}

No comments:

Post a Comment