File.listFiles() mangles unicode names with JDK 6 (Unicode Normalization issues)

前端 未结 6 1051
故里飘歌
故里飘歌 2020-11-30 02:24

I\'m struggling with a strange file name encoding issue when listing directory contents in Java 6 on both OS X and Linux: the File.listFiles() and related metho

6条回答
  •  独厮守ぢ
    2020-11-30 02:57

    I suspect that you just have to instruct javac what encoding to use to compile the .java file containing the special characters with since you've hardcoded it in the source file. Otherwise the platform default encoding will be used, which may not be UTF-8 at all.

    You can use the VM argument -encoding for this.

    javac -encoding UTF-8 com/example/Foo.java

    This way the resulting .class file will end up containing the correct characters and you will be able to create and list the correct filename as well.

提交回复
热议问题