gpt4 book ai didi

java - 如何在groovy中打印特殊字符

转载 作者:太空宇宙 更新时间:2023-11-04 07:52:06 25 4
gpt4 key购买 nike

我想打印 √ (\u221A) http://www.fileformat.info/info/unicode/char/221a/index.htm groovy 中的字符

file = new File("log.txt")
if(!file.exists()){
file.createNewFile()
}

file.withWriter('UTF-8'){
file.write("\u221A √")
}

我在十六进制编辑器中得到3F 20 E2 3F 9A

我不知道为什么会发生这种情况。在第二种情况下,它看起来类似于 0xE2 0x88 0x9A,这是该字符的正确 UTF-8。

我尝试使用选项 -c UTF-8 运行 groovy,但得到 3F 20 3F

最佳答案

事实证明我需要

JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8 

在我的 Windows 环境变量中。

关于java - 如何在groovy中打印特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14267768/

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