public static URI toURI ( final String file ) { if ( file == null ) { return null ; } if ( File . separatorChar == ' ' && file . indexOf ( ' ' ) != - 1 ) { return toURI ( new File ( file ) ) ; } try { return new URI ( file ) ; } catch ( final URISyntaxException e ) { try { return new URI ( clean ( file . replace ( WINDOWS_SEPARATOR , URI_SEPARATOR ) . trim ( ) , false ) ) ; } catch ( final URISyntaxException ex ) { throw new IllegalArgumentException ( ex . getMessage ( ) , ex ) ; } } }
Covert file reference to URI . Fixes directory separators and escapes characters .