public static IFileContentResultBean compareFileContentByBytes ( final File sourceFile , final File fileToCompare ) { final IFileContentResultBean fileContentResultBean = new FileContentResultBean ( sourceFile , fileToCompare ) ; completeCompare ( fileContentResultBean ) ; final boolean simpleEquality = validateEquality ( fileContentResultBean ) ; boolean contentEquality = true ; // Compare the content... if ( simpleEquality ) { try ( InputStream sourceReader = StreamExtensions . getInputStream ( sourceFile ) ; InputStream compareReader = StreamExtensions . getInputStream ( fileToCompare ) ; ) { final byte [ ] source = StreamExtensions . getByteArray ( sourceReader ) ; final byte [ ] compare = StreamExtensions . getByteArray ( compareReader ) ; for ( int i = 0 ; 0 < source . length ; i ++ ) { if ( source [ i ] != compare [ i ] ) { contentEquality = false ; break ; } } } catch ( final FileNotFoundException e ) { contentEquality = false ; } catch ( final IOException e ) { contentEquality = false ; } } fileContentResultBean . setContentEquality ( contentEquality ) ; return fileContentResultBean ; }
Compare file content for every single byte .