Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Lossless reading of a file (line-separators are preserved).
- * May temporarily require memory several times the size of the
- * file. For a short time the raw file contents (a byte array),
- * and the decoded characters reside in memory simultaneously.
- * It is safest to apply to files that you know to be small
- * relative to the available memory.
- * @param path the absolute path of the file.
- * @param encoding the charset with which the bytes in the file
- * should be decoded.
- */
- public static String readFile(String path, Charset encoding)
- throws IOException {
- byte[] encoded = Files.readAllBytes(Paths.get(path));
- return new String(encoded, encoding);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement