In a particular program, I am passed a file: URL and I need to convert it to a URI object. Using the toURI method will throw a java.net.URISyntaxException if there are spaces or any other invalid characters in the URL.
For example:
URL url = Platform.getInstallURL(); // file:/Applications/Program
System.out.println(url.toURI()); // prints file:/Applications/Program
URL url = Platform.getConfigurationURL(); // file:/Users/Andrew Eisenberg
System.out.println(url.toURI()); // throws java.net.URISyntaxException because of the space
What is the best way of performing this conversion so that all special characters are handled?