file io - Java FileOutputStream save the filename with other charset in system -


I have trouble in file name charset when using FileOutputStream.

My code is very simple

  file  

as the parameter file Use the object.

But in my application, the path file is printed correctly on the file System.out.println () .

But on disk, it has been saved using the other charset (I do not know what is).

For example: on System.out.println is outside:

C: \ folder \ MyLatinNameWithCorÃorAnotheLatinChar

But the actual disk file name is the name written in:

C: \ folder \ mitlinename with §orà £ orAnotheLatinChar

what's happening is?

Sorry about the noob question, but I really have problems with it.

system.out is not very reliable.

It is better to observe the string directly to see if it is correct:

  Private static zero debug print (string straight) {for (char ch: str .toCharArray ()) {if (ch & lt; '' || f & gt; '~') {System.out.format ("\\ u% 04x", (int) ch); } Else {System.out.print (ch); }}}  

This view will print out the escape form of anything outside the ASCII range - Ç becomes \ u007c . After this you can check the values ​​to actually see in the string. The problem here is probably extending from the number of characters encoding in Windows:

  • "Unicode" (UTF-16 LE-
  • (Launched with Windows) / Li>

All but Unicode has been deprecated and for all reasons for previous compatibility Some hangs up, but unknowingly corrupt data regularly. When Java was introduced, adopting Unicode was not comprehensive and was to continue on Windows.

Some devrlopers feed in a file.encoding property but by default they change and this can affect the original code call.


Comments