public static File getCanonicalFileFromFileUrl ( final URL url ) { File file = null ; if ( url == null ) { throw new NullPointerException ( "The URL cannot be null." ) ; } if ( "file" . equals ( url . getProtocol ( ) ) ) { final String fileName = url . getFile ( ) ; final String path = URLUtils . uncorrect ( fileName ) ; file = new File ( path ) ; try { file = file . getCanonicalFile ( ) ; } catch ( final IOException e ) { // Does not exist. file = file . getAbsoluteFile ( ) ; } } return file ; }
On Windows names of files from network neighborhood must be corrected before open .