0

I want to run a java class from the command line (cmd) on windows with a parameter (path to a folder) that has utf-8 characters like this:

java <MyClass> "mypath/Časdf"

This produces the following error message:

Could not find the source folder: mypath\Casdf

As you can see, the first character Č has changed to C. This also happens with other special characters. I already tried the following:

  • change the codepage of the windows cmd to 65001 before executing java
  • execute java with option -Dfile.encoding=UTF8
  • execute java with PowerShell
  • execute java in a Linux environment: no problem there, but I need to be able to execute it in Windows (and preferably with cmd)
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Irina S.
  • 133
  • 8
  • Unsure whether it is a true duplicate, but the answers to [Passing command line unicode argument to Java code](https://stackoverflow.com/q/7660651/3545273) could help – Serge Ballesta Mar 07 '19 at 16:35
  • Hi @SergeBallesta, thanks a lot for the link. It is indeed the same problem there and some helpful answers/explanations! – Irina S. Mar 08 '19 at 09:03

1 Answers1

0

Doing a dir inside cmd.exe will show the basic latin letter, when the accented letter is not in the console's encoding.

Letting cmd expand an argument * will pass the correct string to main's args.

Path path = Paths.get("C:\\test\\mypath", args[0]);

One can also do normal file operations on the path.

My guess is that you are writing a .cmd/.bat file with that file name on a system were the Č is not displayable. Then cmd reading the .cmd file will fall back on basic unaccented letters. Also pasting from Windows into a cmd console might not be possible (if you are not in Czechia/Slovakia).

With my charset, "Cp850", I indeed did see ü but not Č (shown as C).

A hard coded path in java needs for instance have the IDE use UTF-8 for the editor and also for the javac compiler.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138