I am trying to copy a file on an ubuntu machine using the java statement
Files.copy(new File("/tmp/source/测试.xlsx").toPath(), new File("/tmp/dest/测试.xlsx").toPath(), StandardCopyOption.REPLACE_EXISTING);
But i get the following error
java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: /tmp/source/测试.xlsx at sun.nio.fs.UnixPath.encode(UnixPath.java:147) ~[na:1.8.0_91] at sun.nio.fs.UnixPath.(UnixPath.java:71) ~[na:1.8.0_91] at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:281) ~[na:1.8.0_91] at java.io.File.toPath(File.java:2234) ~[na:1.8.0_91]
This runs perfectly fine when i run it on my eclipse. Also, the code works fine with all english characters.
This could be a JDK Bug
Set the following system properties sun.jnu.encoding=UTF-8
and file.encoding=UTF-8
.
-D
option if you are running a java
program in command line. (-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With