Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read next character (full unicode code point) from Java input stream

Tags:

java

utf-8

I need to parse UTF-8 input (from a text file) character by character (and by character I mean full UTF-8 character (UTF-8 code point), not Java's char).

What approach should I use?

like image 868
zduny Avatar asked Nov 23 '22 10:11

zduny


1 Answers

There's CharSequence.codePoints()

For example:

String text = Files.readString(Path.of("test.txt"));

IntStream codePoints = text.codePoints();

// do something with the code points
codePoints.forEach(codePoint -> System.out.println(codePoint));
like image 160
Arend v. Reinersdorff Avatar answered Nov 24 '22 23:11

Arend v. Reinersdorff