Reading entire contents of file at a given java.no.file.Path into a String
I believe you are missing a relatively obvious, although somewhat memory-inefficient Files.readAllBytes(...) .... Consider this:

public String readFile(Path path, Charset encoding) throws IOException {
    return new String(Files.readAllBytes(path), encoding);
}


In your code you also have two full copies of the file in-memory at one time, so the files can't be huge. The code I suggest also pulls all the data in to memory twice, once as a byte[] array, which gets converted to a String, and the byte[] array is discarded.

There would be a loopy way to solve it by using a StringBuilder and a smaller byte[] array, or ByteBuffer, but, if your files are smallish, I would not worry about the byte[] size.