Skip to content

Instantly share code, notes, and snippets.

@jlmelville
Created October 31, 2015 21:23
Show Gist options
  • Save jlmelville/581b699342b83ac47da9 to your computer and use it in GitHub Desktop.
Save jlmelville/581b699342b83ac47da9 to your computer and use it in GitHub Desktop.
Encoding-aware handling of text files in Java
try (InputStreamReader inputStreamReader = new InputStreamReader(
new FileInputStream(path.toString()), StandardCharsets.UTF_8)) {
// do stuff with the inputStreamReader rather than a File
}
}
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
String string = new String(bytes, StandardCharsets.UTF_8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment