Created
October 31, 2015 21:23
-
-
Save jlmelville/581b699342b83ac47da9 to your computer and use it in GitHub Desktop.
Encoding-aware handling of text files in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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