public File rel2abs ( final String basePath , final String relPath ) { String [ ] baseParts = getParts ( basePath ) ; String [ ] relParts = getParts ( relPath ) ; if ( isAbsolutePath ( relPath ) ) { return new File ( relPath ) ; } List < String > parts = new ArrayList <> ( ) ; for ( int i = 0 ; i < baseParts . length ; ++ i ) { if ( i > 0 || ! isWindowsDrive ( basePath ) ) { parts . add ( baseParts [ i ] ) ; } } for ( String part : relParts ) { if ( part . equals ( ".." ) && parts . size ( ) > 0 ) { parts . remove ( parts . size ( ) - 1 ) ; } else if ( ! part . equals ( "." ) && ! part . equals ( ".." ) ) { parts . add ( part ) ; } } StringBuilder result = new StringBuilder ( ) ; if ( isWindowsDrive ( basePath ) ) { result . append ( baseParts [ 0 ] ) ; } for ( String part : parts ) { result . append ( File . separator ) ; result . append ( part ) ; } return new File ( result . toString ( ) ) ; }
Converts an relative path into an absolute one .