RosettaCodeData/Task/Read-a-file-character-by-character-UTF8/Java/read-a-file-character-by-character-utf8-1.java

21 lines
514 B
Java
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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();
}
}