Encoding the contents of a file name has nothing to do with the encoding of the file name itself.
You should get the correct results from System.out.println(insert)
If you do not, this means that the shell has a different character encoding, which is encoded by default for your system (this rarely happens, this is usually the result of an explicit command to switch encodings in the shell).
If the file names are displayed correctly when you specify the directory in the shell, I expect them to be displayed correctly without specifying the encoding in your Java program.
If the shell is unable to display the character (it replaces the replacement character 0xFFFD (& # xFFFD;) for these non-printable characters), you cannot do anything from your Java application to change this. You need to change the character encoding of the terminal, install the correct fonts, etc .; this is an operating system problem, not a Java problem.
At the same time, even if your terminal cannot display the correct results, the Java program must correctly process character encodings without your intervention.
The API File library calculates the correct character encoding for your system and makes the necessary character decoding. Likewise, the database driver must negotiate with the database to determine the correct encoding and do any necessary encoding in bytes on behalf of your application.
source share