gpt4 book ai didi

java - Java 中的新字形?

转载 作者:行者123 更新时间:2023-12-01 18:07:40 28 4
gpt4 key购买 nike

有没有办法在java中读取新的unicode字符或字形,例如长青绿(U+1F332),山(U+26F0)和穿西装的男人(U+1F574) ?我真的很想将其实现到我正在编写的游戏中,但我不知道如何实现。 Apache的扩展库 Not Acceptable ,抱歉。

最佳答案

正如我在评论中暗示的那样,您的问题不太可能是阅读字符。 Java 应该能够很好地读取(并写入)它们。例如:

import java.io.*;

public class NewChars {

public static void main(String[] args) throws IOException {
// UTF-16 (surrogate pairs) for the two characters mentioned:
String theChars = "\ud87c\udf32\ud87e\udd74";

// Write the characters to a (UTF-8 encoded) byte stream:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer out = new OutputStreamWriter(baos, "UTF-8");

out.write(theChars);
out.close();

// Read the characters back
BufferedReader in = new BufferedReader(new InputStreamReader(
new ByteArrayInputStream(baos.toByteArray()), "UTF-8"));
String readBack = in.readLine();

// Check the result (prints "Readback is good"):
System.out.println(theChars.equals(readBack) ? "Readback is good"
: "Readback is bad");
}
}

问题很可能是您的系统没有包含这些字符的字形的字体。您描述的看到的字形(内部带有问号的正方形或菱形)是在所选字体没有其他字形的字符位置发出的常用替换字形之一。

这不是 Java 问题。您需要更新的字体,可能来自您的操作系统供应商,它们可能可用,也可能不可用。此外,明智的做法是避免依赖其他可能没有支持字体的字符,除非您只想让您的程序在您开发它的计算机上按预期工作。

关于java - Java 中的新字形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35071139/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com