static public boolean areOnSameFileStore ( File a , File b ) throws RolloverFailure { if ( ! a . exists ( ) ) { throw new IllegalArgumentException ( "File [" + a + "] does not exist." ) ; } if ( ! b . exists ( ) ) { throw new IllegalArgumentException ( "File [" + b + "] does not exist." ) ; } // Implements the following by reflection // Path pathA = a.toPath(); // Path pathB = b.toPath(); // // FileStore fileStoreA = Files.getFileStore(pathA); // FileStore fileStoreB = Files.getFileStore(pathB); // // return fileStoreA.equals(fileStoreB); try { Class < ? > pathClass = Class . forName ( PATH_CLASS_STR ) ; Class < ? > filesClass = Class . forName ( FILES_CLASS_STR ) ; Method toPath = File . class . getMethod ( "toPath" ) ; Method getFileStoreMethod = filesClass . getMethod ( "getFileStore" , pathClass ) ; Object pathA = toPath . invoke ( a ) ; Object pathB = toPath . invoke ( b ) ; Object fileStoreA = getFileStoreMethod . invoke ( null , pathA ) ; Object fileStoreB = getFileStoreMethod . invoke ( null , pathB ) ; return fileStoreA . equals ( fileStoreB ) ; } catch ( Exception e ) { throw new RolloverFailure ( "Failed to check file store equality for [" + a + "] and [" + b + "]" , e ) ; } }
This method assumes that both files a and b exists .