Advertisement
Guest User

Untitled

a guest
May 29th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /**
  2. * Lossless reading of a file (line-separators are preserved).
  3. * May temporarily require memory several times the size of the
  4. * file. For a short time the raw file contents (a byte array),
  5. * and the decoded characters reside in memory simultaneously.
  6. * It is safest to apply to files that you know to be small
  7. * relative to the available memory.
  8. * @param path the absolute path of the file.
  9. * @param encoding the charset with which the bytes in the file
  10. * should be decoded.
  11. */
  12. public static String readFile(String path, Charset encoding)
  13. throws IOException {
  14. byte[] encoded = Files.readAllBytes(Paths.get(path));
  15. return new String(encoded, encoding);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement