Greetings to all!

Tell me how to get the correct file path? I pass a link to the file with the following name in the arguments:

GovHK 政府 一 站 通 : Homepage (Residents) .webloc

And instead of the name I get the following:

GovHK ???????: Homepage (Residents) .webloc

Respectively file.exists(); displays false;

As far as I dug on the Internet, this is ISO-8859-10 and Java does not support it. I did not find a complete solution for decoding a string, so I’ll appeal to you.

Thank you in advance!

UPD Conjure a simple equivalent of code:

 public class Test { public static void main(String[] args) { if (args.length > 0) { File file = new File(args[0]); System.out.println("Exists: " + file.exists()); } } } 

And the file is uploaded here: file

  • one
    Just checked: created a file with the name as indicated by D:\\GovHK 香港政府一站通:Homepage (Residents).webloc and returned true. Maybe it makes sense to also attach your code, and maybe even a file, to eliminate inaccuracies? - Mikita Berazouski September
  • one
    Just checked - it works. And show how you call the program and how you pass the parameters. - Mikita Berazouski September
  • one
    The problem is not in the program, but in the windows console, which translates signs into questions. - Mikita Berazouski September
  • one
    Well, everything works correctly through the intellij idea. And so now I myself look, if I find something, I will unsubscribe. - Mikita Berazouski September
  • one
    Wait, what does it mean to get it? You have the file - you attached it. Or do you mean programmatically rename? - Mikita Berazouski September

1 answer 1

As stated above, the problem lies in the encoding of the console, and not in the application itself. In order to correctly change the console encoding, it is often enough to execute the chcp command, for example, for UTF8, this is chcp 65001 . But in your particular case this will not be enough. In essence, you need encoding 936. However, if you issue the chcp 936 command, you will see the message Invalide code page . To get rid of this, you need to change the region. To do this, take the following steps:

  1. Start - Control Panel
  2. Choose "Region and Language" enter image description here
  3. Next, go to the "Administrative" tab and select "Change system locale" enter image description here
  4. In the drop-down list, select "Chinese (Simplified, RPC)" enter image description here
  5. Reboot the computer

This is not a change in the interface of the entire operating system.

After that, when you run the chcp command chcp output will be Active code page: 936 . Now you can run your application - the result will be true : enter image description here

It seems that this is what you are looking for.