gpt4 book ai didi

java - ConEmu (CMD) 无法识别这些 un​​icode 字符?

转载 作者:行者123 更新时间:2023-12-02 10:23:57 26 4
gpt4 key购买 nike

public void print(boolean nextLine, int delayInt, String load) throws UnsupportedEncodingException {
PrintStream p = new PrintStream(System.out, true,"UTF-8");
for(int x = 0; x < load.length(); x++ ){
p.print(load.charAt(x));
try{
Thread.sleep(delayInt);
}catch (Exception ex){
ex.printStackTrace();
}
}
if(nextLine)
System.out.println();
}

好吧,上面是打印字符串中每个字符的方法,我使用 PrintStream 是因为我觉得当我在 ConEmu 中编译和执行 Java 程序时,它允许我使用所有 Unicode 字符(我正在使用它而不是CMD @ Windows)

i.print(true, 50,"\n" +
"\n" +
"▓█████▄ ██▓ ██████ ▄████▄ ▒█████ ██▒ █▓ ▓█████ ██▀███ \n" +
"▒██▀ ██▌ ▓██▒ ▒██ ▒ ▒██▀ ▀█ ▒██▒ ██▒ ▓██░ █▒ ▓█ ▀ ▓██ ▒ ██▒ \n" +
"░██ █▌ ▒██▒ ░ ▓██▄ ▒▓█ ▄ ▒██░ ██▒ ▓██ █▒░ ▒███ ▓██ ░▄█ ▒ \n" +
"░▓█▄ ▌ ░██░ ▒ ██▒ ▒▓▓▄ ▄██▒ ▒██ ██░ ▒██ █░░ ▒▓█ ▄ ▒██▀▀█▄ \n" +
"░▒████▓ ░██░ ▒██████▒▒ ▒ ▓███▀ ░ ░ ████▓▒░ ▒▀█░ ░▒████▒ ░██▓ ▒██▒ \n" +
" ▒▒▓ ▒ ░▓ ▒ ▒▓▒ ▒ ░ ░ ░▒ ▒ ░ ░ ▒░▒░▒░ ░ ▐░ ░░ ▒░ ░ ░ ▒▓ ░▒▓░ \n" +
" ░ ▒ ▒ ▒ ░ ░ ░▒ ░ ░ ░ ▒ ░ ▒ ▒░ ░ ░░ ░ ░ ░ ░▒ ░ ▒░ \n" +
" ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░░ ░ \n" +
" ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ \n" +
" ░ ░ ░ \n" +
"\n"
);
i.print(true, 2, "\n" +
"\n" +
" ▄█ ▄████████ \n" +
"███ ███ ███ \n" +
"███▌ ███ ███ \n" +
"███▌ ███ ███ \n" +
"███▌ ▀███████████ \n" +
"███ ███ ███ \n" +
"███ ███ ███ \n" +
"█▀ ███ █▀ \n" +
" \n" +
" ▄█ ▄█ ▄█ ▀█████████▄ ▄████████ ▄█ ▄████████ ▄█ ▄█▄ ▄█ ▄█ ▄█ \n" +
"███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄███▀ ███ ███ ███ \n" +
"███▌ ███▌ ███▌ ███ ███ ███ ███ ███▌ ███ █▀ ███▐██▀ ███▌ ███▌ ███▌ \n" +
"███▌ ███▌ ███▌ ▄███▄▄▄██▀ ▄███▄▄▄▄██▀ ███▌ ███ ▄█████▀ ███▌ ███▌ ███▌ \n" +
"███▌ ███▌ ███▌ ▀▀███▀▀▀██▄ ▀▀███▀▀▀▀▀ ███▌ ███ ▀▀█████▄ ███▌ ███▌ ███▌ \n" +
"███ ███ ███ ███ ██▄ ▀███████████ ███ ███ █▄ ███▐██▄ ███ ███ ███ \n" +
"███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ \n" +
"█▀ █▀ █▀ ▄█████████▀ ███ ███ █▀ ████████▀ ███ ▀█▀ █▀ █▀ █▀ \n" +
" ███ ███ ▀ \n" +
" ▄█ ▄█ ▄█ ▀█████████▄ ▄████████ ▄████████ ▄████████ ▄█ ▄█▄ ▄████████ ▄████████ ▄█ ▄█ ▄█ \n" +
"███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄███▀ ███ ███ ███ ███ ███ ███ ███ \n" +
"███▌ ███▌ ███▌ ███ ███ ███ ███ ███ █▀ ███ ███ ███▐██▀ ███ █▀ ███ ███ ███▌ ███▌ ███▌ \n" +
"███▌ ███▌ ███▌ ▄███▄▄▄██▀ ▄███▄▄▄▄██▀ ▄███▄▄▄ ███ ███ ▄█████▀ ▄███▄▄▄ ▄███▄▄▄▄██▀ ███▌ ███▌ ███▌ \n" +
"███▌ ███▌ ███▌ ▀▀███▀▀▀██▄ ▀▀███▀▀▀▀▀ ▀▀███▀▀▀ ▀███████████ ▀▀█████▄ ▀▀███▀▀▀ ▀▀███▀▀▀▀▀ ███▌ ███▌ ███▌ \n" +
"███ ███ ███ ███ ██▄ ▀███████████ ███ █▄ ███ ███ ███▐██▄ ███ █▄ ▀███████████ ███ ███ ███ \n" +
"███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ ███ ███ ███ ███ \n" +
"█▀ █▀ █▀ ▄█████████▀ ███ ███ ██████████ ███ █▀ ███ ▀█▀ ██████████ ███ ███ █▀ █▀ █▀ \n" +
" ███ ███ ▀ ███ ███ \n" +
" ▄█ ▄█ ▄█ ▄████████ ▄████████ ████████▄ ███ █▄ ▄████████ ▄█ ▄█ ▄█ ▄█ \n" +
"███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ \n" +
"███▌ ███▌ ███▌ ███ █▀ ███ █▀ ███ ███ ███ ███ ███ █▀ ███ ███▌ ███▌ ███▌ \n" +
"███▌ ███▌ ███▌ ███ ▄███▄▄▄ ███ ███ ███ ███ ▄███▄▄▄ ███ ███▌ ███▌ ███▌ \n" +
"███▌ ███▌ ███▌ ▀███████████ ▀▀███▀▀▀ ███ ███ ███ ███ ▀▀███▀▀▀ ███ ███▌ ███▌ ███▌ \n" +
"███ ███ ███ ███ ███ █▄ ███ ███ ███ ███ ███ █▄ ███ ███ ███ ███ \n" +
"███ ███ ███ ▄█ ███ ███ ███ ███ ▀ ███ ███ ███ ███ ███ ███▌ ▄ ███ ███ ███ \n" +
"█▀ █▀ █▀ ▄████████▀ ██████████ ▀██████▀▄█ ████████▀ ██████████ █████▄▄██ █▀ █▀ █▀ \n" +
" ▀ \n" +
" ▄█ \n" +
"███ \n" +
"███▌ \n" +
"███▌ \n" +
"███▌ \n" +
"███ \n" +
"███ \n" +
"█▀ \n" +
" \n" +
"\n" +
" \n");

但是,在 IDE 上,它确实可以运行,但在 ConEmu 上它显示,“testing.java:50: 错误: 无法映射的字符 (0x90) 用于编码 windows-1252” 错误 我已经检查了解决方案,但它们仅适用于当我有 '\uXXXX' 字符代码时,在这种情况下我没有我使用了在线 ASCII 艺术生成器。 ASCII ART Generator which I have used

最佳答案

根据ConEmu documentation :

UTF-8 (UTF8)

On Windows, unlike Unix, the console itself is not a stream of ‘bytes’ but a spreadsheet of cells, each of which contains an UTF-16 character and a color attribute.

That means if your application produces output using single-byte or multi-byte character sets (which are ANSI, OEM, UTF-8 and many others) the Windows converts that output to UTF-16 automatically regarding active codepage selected in your console (run chcp from console command prompt to check your active codepage).

If you want to work with UTF-8 encoding you have to select UTF-8 as active console codepage. Just run chcp 65001 command to do that. You may call this command from your shell prompt or run it before shell in a ConEmu task content. Of course your application must be able to output data using UTF-8. Refer to your application manual.

只需输入您的 ConEmu 终端,您就可以看到 UTF-8 内容:

chcp 65001

您还必须稍微修改一下源代码并将其另存为 UTF-8 文件:

public void print(boolean nextLine, int delayInt, String load) throws UnsupportedEncodingException {
for(int x = 0; x < load.length(); x++ ){

// Use the regular System.out.print here to output chars!
System.out.print(load.charAt(x));

try{
Thread.sleep(delayInt);
}catch (Exception ex){
ex.printStackTrace();
}
}
if(nextLine)
System.out.println();
}

编译运行脚本:

chcp 65001
java test

我在 ConEmu 控制台中得到的结果: enter image description here

关于java - ConEmu (CMD) 无法识别这些 un​​icode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54117211/

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