public static boolean isRelativePath ( String path ) { if ( path . startsWith ( "/" ) ) return false ; if ( path . startsWith ( "\\\\" ) && path . length ( ) > 3 && path . indexOf ( ' ' , 3 ) != - 1 ) return false ; // a UNC path which is the most absolute you can get on windows if ( path . length ( ) >= 3 && ' ' == path . charAt ( 1 ) ) { // never mind that the drive mappings can be changed between sessions, we just want to // know if the 3rd character is a `\` (or a '/' is acceptable too) char p = path . charAt ( 0 ) ; if ( ( ' ' <= p && p <= ' ' ) || ( ' ' <= p && p <= ' ' ) ) { return path . charAt ( 2 ) != ' ' && path . charAt ( 2 ) != ' ' ; } } return true ; }
A mostly accurate check of whether a path is a relative path or not . This is designed to take a path against an unknown operating system so may give invalid results .