When the application is deployed, a file read error occurs, a folder name that contains spaces in the deployment path, and the application server location is migrated.
Find the following solutions online:
1, Testurl (). Class.getResource (""). GetPath () or Testurl (). Class.getResource (""). GetFile () The path obtained cannot be FileReader () and FileWriter () direct application.
The reason is that the URL is encoded with spaces, special characters (%,#,[], and so on) and Chinese.
For example: The space becomes% 20.
There is a workaround (1), after replacing with Repaceall ("%20", ""), only the space problem can be resolved. But the path contains% and Chinese is not.
There is a workaround (2), using Urldecoder.decode (str, "UTF-8") decoding, but only part of the solution, if the path contains +, also cannot be resolved, because the URL is not fully used Urlencoder.encode (str, "UTF-8 ") encoded, the + number is decoded, but it becomes a space.
Method (3), you can solve all the problems, with Testurl (). Class.getResource (""). Touri (). GetPath (), but you need to handle the urisyntaxexception exception, which is a bit more troublesome.
Source: http://blog.chinaunix.net/uid-11898547-id-3671219.html
Java read file path space and Chinese processing