RosettaCodeData/Task/Read-a-file-character-by-character-UTF8/Java/read-a-file-character-by-character-utf8-1.java
2023-07-01 13:44:08 -04:00

20 lines
514 B
Java

import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class Program {
private final FileReader reader;
public Program(String path) throws IOException {
reader = new FileReader(path, StandardCharsets.UTF_16);
}
/** @return integer value from 0 to 0xffff, or -1 for EOS */
public int nextCharacter() throws IOException {
return reader.read();
}
public void close() throws IOException {
reader.close();
}
}