Problem:
The correct path is not found when the Java project path contains Chinese
***
Solve:
This is actually a problem with coding conversions. When we get the path using ClassLoader's GetResource method, the obtained path is encoded by Urlencoder.encode (path, "Utf-8"), and when there are Chinese and white spaces in the path, he converts the characters, so that is often not the real path we want, so we can call the Urldecoder.decode () method to decode, in order to get the original Chinese and white space path.
Java code:
String PackagePath = Url.getpath (). ReplaceAll ("%20", "");//resolve Path with spaces
PackagePath = Java.net.URLDecoder.decode (PackagePath, "utf-8"); To resolve paths that contain Chinese
***
Results:
/d:/java%e7%a8%8b%e5%ba%8f%ef%bc%88idea)/smartframework/core/target/classes/
After decoding:/d:/java program (IDEA)/smartframework/core/target/classes/
***
About decoding and encoding
Urlencoder.encode (string s, String enc)
Converts a string to the application/x-www-form-urlencoded format using the specified encoding mechanism
Urldecoder.decode (string s, String enc)
Decodes a application/x-www-form-urlencoded string using the specified encoding mechanism.
When sending using Urlencoder.encode encoding, when receiving the use of Urldecoder.decode decoding, all in accordance with the specified encoding format encoding, decoding, can ensure that no garbled
Troubleshoot Java engineering paths that contain Chinese