Here you can find the source of readFileToString(@Nonnull Path file)
@Nonnull public static String readFileToString(@Nonnull Path file) throws IOException
//package com.java2s; //License from project: Mozilla Public License import javax.annotation.Nonnull; import java.io.FileReader; import java.io.IOException; import java.nio.file.Path; public class Main { /**/*www.j a va2 s .co m*/ * @return The contents of the file, with linebreaks included */ @Nonnull public static String readFileToString(@Nonnull Path file) throws IOException { StringBuilder sb = new StringBuilder(); try (FileReader fr = new FileReader(file.toFile())) { int chr; while ((chr = fr.read()) != -1) { sb.append((char) chr); } } return sb.toString(); } }