Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3339042
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:26:48+00:00 2026-05-18T00:26:48+00:00

My Windows’s default encoding is GBK, and my Eclipse is totally utf-8 encoded. So

  • 0

My Windows’s default encoding is GBK, and my Eclipse is totally utf-8 encoded.
So an application which runs well in my Eclipse, crashes because the words become unreadable when exported as a jar file;
I have to write the following line in a .bat file to run the application

   start java -Dfile.encoding=utf-8 -jar xxx.jar    

Now my question is that can I write something in the source code to set the application uses(or the jvm runs in) utf-8 instead of the system’s default encoding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:26:48+00:00Added an answer on May 18, 2026 at 12:26 am

    When you open a file for reading, you need to explicitly specify the encoding you want to use for reading the file:

    Reader r = new InputStreamReader(new FileInputStream("myfile"), StandardCharsets.UTF_8);
    

    Then the value of the default platform encoding (which you can change using -Dfile.encoding) no longer matters.

    Note:

    I would normally recommend to always specify the encoding explicitly for any operation that depends on the standard locale, such as character I/O. Many Java API methods default to the platform encoding, which I consider a bad design, because often the platform encoding is not the right one, plus it may suddenly change (if the user e.g. switches OS locale), breaking your app.

    So just always say which encoding you want.

    There are some cases where the platform encoding is the right one (such as when opening a file the user just created for you), but they are fairly rare.

    Note 2:

    java.nio.charset.StandardCharsets was introduced in Java 1.7. For older Java versions, you need to specify the input encoding as a String (ugh). The list of possible encodings depends on the JVM, but every JVM is guaranteed to at least have:

    US-ASCII, ISO-8859-1,UTF-8,UTF-16BE,UTF-16LE,UTF-16.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Windows form application(.Net 3.5) I have a textbox and a button on the form.
Windows has VirtualAlloc, which allows you to reserve a contiguous region of address space,
Windows Phone 7.1 supports SQL Server CE and LINQ to SQL, as well as
Windows form application. C# 4.0. Basically I have two datagridviews dgv1 and dgv2. One
Windows Form Application – Manipulating input-elements in WinForm WebBrowser Although I am familiar with
Windows has GetFileTime API which allows getting file time information by open file handle.
Windows 6 (Vista and Server 2008) support proper symbolic links, which can be created
Windows API ::FindWindow function fails when called from Service application. GetLastError() also returns 0
Windows phone asks for specific image sizes when submitting an application. When I take
Windows Mobile 6.5 I have a process which uses System.Threading.Timer upload some data to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.