为什么在我的Visual Studio Code上的Java项目中,表情符号打印为奇怪的符号?

huangapple go评论69阅读模式
英文:

Why do emojis print as weird symbols in my Java project on Visual Studio Code?

问题

Displaying UTF-8 Emojis in Java

我尝试在Visual Studio Code的Java中打印表情符号,例如 "🚢",但它会将每个表情符号替换为 "?"。
我尝试在网上找到解决方案,并发现通过导入以下内容:

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;

我可以使用新的 PrintStream 进行打印,这使我写出了以下代码:

PrintStream ps = new PrintStream(new FileOutputStream(FileDescriptor.out), true, StandardCharsets.UTF_8);
ps.println("🚢");

然而,这只返回了意外的符号 "≡ƒÜó"。
我该如何使它显示预期的表情符号?

英文:

Displaying UTF-8 Emojis in java

I'm trying to print emojis such as "🚢" in java on Visual Studio Code, but it would replace every emoji with a "?"
I tried to find solutions online and found that by importing:

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;

I could print using a new printStream, which got me to:

 PrintStream ps = new PrintStream(new FileOutputStream(FileDescriptor.out), true, StandardCharsets.UTF_8);
 ps.println("🚢");

However, this only returned unintended symbols "🚢".
How can I get it to display the intended emojis?

答案1

得分: 1

在我在VS Code和IntelliJ IDEA中都可以正常工作。

请检查您的终端和文件编码设置。

英文:

It works for me in both VS Code and IntelliJ IDEA.

Please check your settings for terminal and file encoding.

为什么在我的Visual Studio Code上的Java项目中,表情符号打印为奇怪的符号?

huangapple
  • 本文由 发表于 2023年6月1日 13:45:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定