, Windows Latin-1, UTF-8.
private static final String FILE_PATH = "c:\\temp\\test.txt";
Path path = Paths.get(FILE_PATH);
Charset charset = Charset.forName("Windows-1252");
try (BufferedReader in = Files.newBufferedReader(path, charset)) {
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
}
line . , System.out Unicode , Unicode.
System.out.println("My encoding is: " + System.getProperty("file.encoding"));
, , ? char. char, UTF-8 - .
Unicode .
é:
String e = "\u00e9";
String s = new String(Files.readAllBytes(path), charset);
System.out.println("Contains e´ : " + s.contains(e));
:
Files.newBufferedReader( ), .
try (BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(file), charset))) {
These are buffers for faster reading, and InputStreamReader uses InputStream binary data plus encoding to convert to Unicode Reader.
source
share