Encoding issue on filename with Java 7 on OSX with jnlp/webstart

后端 未结 5 1172
孤街浪徒
孤街浪徒 2021-02-05 22:31

I have this problem that has been dropped on me, and have been a couple of days of unsuccessful searches and workaround attempts.

I have now an internal java swing prog

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 22:58

    It's a bug in the old-skool java File api, maybe just on a mac? Anyway, the new java.nio api works much better. I have several files containing unicode characters and content that failed to load using java.io.File and related classes. After converting all my code to use java.nio.Path EVERYTHING started working. And I replaced org.apache.commons.io.FileUtils (which has the same problem) with java.nio.Files...

    ...and be sure to read and write the content of file using an appropriate charset, for example:

    Files.readAllLines(myPath, StandardCharsets.UTF_8)
    

提交回复
热议问题