加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 通过codepoint读取文本流代码点

发布时间:2020-12-15 01:09:45 所属栏目:Java 来源:网络整理
导读:我正在尝试从Java中的文本文件中读取Unicode代码点. InputStreamReader类通过int返回流的内容int,我希望它可以做我想要的,但它不构成代理对. 我的测试程序: import java.io.*;import java.nio.charset.*;class TestChars { public static void main(String

我正在尝试从Java中的文本文件中读取Unicode代码点. InputStreamReader类通过int返回流的内容int,我希望它可以做我想要的,但它不构成代理对.

我的测试程序:

import java.io.*;
import java.nio.charset.*;

class TestChars {
    public static void main(String args[]) {
        InputStreamReader reader =
            new InputStreamReader(System.in,StandardCharsets.UTF_8);
        try {
            System.out.print("> ");
            int code = reader.read();
            while (code != -1) {
                String s =
                    String.format("Code %x is `%s',%s.",code,Character.getName(code),new String(Character.toChars(code)));
                System.out.println(s);
                code = reader.read();
            }
        } catch (Exception e) {
        }
    }
}

其行为如下:

$java TestChars 
> keyboard ?. pizza                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读