search
HomeJavaJavaBaseGarbled characters appear when running java projects through bash/cmd

Garbled characters appear when running java projects through bash/cmd

Nov 23, 2019 pm 01:56 PM
bashcmdjavaGarbled charactersrun

Garbled characters appear when running java projects through bash/cmd

Question:

No matter how the Java code is uniformly encoded as UTF8, it is completely fine to run in the IDE, but it is packaged into Jar and run through Bash and CMD. , Chinese garbled characters will appear.

Reason:

The default encoding of cmd/bash is GBK.

Solution:

1. Set the cmd encoding to utf-8

Open cmd and enter the following command:

chcp 65001

This way You can change the encoding of cmd to UTF-8.

The following is the commonly used cmd encoding, as shown in the figure:

Garbled characters appear when running java projects through bash/cmd

2. Specify the encoding method when executing java

Under cmd, The common commands to run Jar packages are as follows:

java -jar project.jar

However, this may cause errors caused by incorrect encoding during java runtime. At this time, we can specify the encoding parameters when running Jar

java -Dfile.encoding=utf-8 -jar project.jar

Three . Package the above commands into a bat

If you have to perform the above two steps every time you start the project, it will actually be very troublesome. We can package the above two steps into a bat batch file. The specific steps are as follows

3.1 Create a txt file in the Jar directory and open it with Notepad

Garbled characters appear when running java projects through bash/cmd

3.2 Write the above command into the txt file and save it

Garbled characters appear when running java projects through bash/cmd

3.3 Modify msgSystemStart.txt to msgSystemStart.bat

Garbled characters appear when running java projects through bash/cmd

##3.4 Run the bat file

Garbled characters appear when running java projects through bash/cmd

You can see that the project starts normally and there will be no garbled code problems.

Recommended tutorial:

java quick start

The above is the detailed content of Garbled characters appear when running java projects through bash/cmd. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool