PS D:\> cd "D:\IdeaProjects\demos"
PS D:\IdeaProjects\demos> ls
目录: D:\IdeaProjects\demos
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2024/9/29 13:24 .idea
d----- 2024/9/29 13:21 src
d----- 2024/9/29 13:24 target
-a---- 2024/9/29 13:12 2461 .gitignore
-a---- 2024/9/29 13:23 2591 pom.xml
-a---- 2024/9/29 13:25 0 Simplified Chinese 简体中文.txt
PS D:\IdeaProjects\demos> java -jar D:\IdeaProjects\demos\target\grabled-chars-1.0-SNAPSHOT-jar-with-dependencies.jar
SLF4J(I): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider]
13:25:49.259 [main] INFO Application -- Simplified Chinese 绠€浣撲腑鏂?
PS D:\IdeaProjects\demos>
From the result of ls ,we can see Simplified Chinese 简体中文.txt is displayed well.
And here is the source code of grabled-chars-1.0-SNAPSHOT-jar-with-dependencies.jar. It is very simple,
@Slf4j
public class Application {
public static void main(String[] args) throws InterruptedException {
log.info("Simplified Chinese 简体中文");
}
}
with Lombok and logback-classic:1.5.8.
But the output in PowerShell is 13:25:49.259 [main] INFO Application -- Simplified Chinese 绠€浣撲腑鏂?
How can I fix this?
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding, see: Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)chcp, show current codepage (2) 3 possible setting , 936(GBK) , 437 , 65001 (UTF-8) (3)PS C:\Users\User\demos-garbled-chars\target> chcp 活动代码页: 936 PS C:\Users\User\demos-garbled-chars\target> java -jar grabled-chars-1.0-SNAPSHOT-jar-with-dependencies.jar SLF4J(I): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider] 04:38:54.128 [main] INFO Application -- Simplified Chinese 简体中文PS C:\Users\User\demos-garbled-chars\target> chcp Active code page: 437 PS C:\Users\User\demos-garbled-chars\target> java -jar grabled-chars-1.0-SNAPSHOT-jar-with-dependencies.jar SLF4J(I): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider] 05:00:32.281 [main] INFO Application -- Simplified Chinese ????(But in en_US, code page 437, Power Shell shows??????, which I think is correct.)$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encodingin powershell, now output ofjar -jaris displayed well!