我剛剛發現這一點位二進制你對谷歌比較法,沒有答應,如果它的工作原理;)
/**
* Compare binary files. Both files must be files (not directories) and exist.
*
* @param first - first file
* @param second - second file
* @return boolean - true if files are binery equal
* @throws IOException - error in function
*/
public boolean isFileBinaryEqual(
File first,
File second
) throws IOException
{
// TODO: Test: Missing test
boolean retval = false;
if ((first.exists()) && (second.exists())
&& (first.isFile()) && (second.isFile()))
{
if (first.getCanonicalPath().equals(second.getCanonicalPath()))
{
retval = true;
}
else
{
FileInputStream firstInput = null;
FileInputStream secondInput = null;
BufferedInputStream bufFirstInput = null;
BufferedInputStream bufSecondInput = null;
try
{
firstInput = new FileInputStream(first);
secondInput = new FileInputStream(second);
bufFirstInput = new BufferedInputStream(firstInput, BUFFER_SIZE);
bufSecondInput = new BufferedInputStream(secondInput, BUFFER_SIZE);
int firstByte;
int secondByte;
while (true)
{
firstByte = bufFirstInput.read();
secondByte = bufSecondInput.read();
if (firstByte != secondByte)
{
break;
}
if ((firstByte < 0) && (secondByte < 0))
{
retval = true;
break;
}
}
}
finally
{
try
{
if (bufFirstInput != null)
{
bufFirstInput.close();
}
}
finally
{
if (bufSecondInput != null)
{
bufSecondInput.close();
}
}
}
}
}
return retval;
}
來源:http://www.java2s.com/Code/Java/File-Input-Output/Comparebinaryfiles.htm
你只需要創建currentFile的File對象,當你想保存你的文件,並將它與你現有的文件進行比較;)
對我來說,似乎是一個布爾值是最好的解決方案。事實上,你有一個廣泛和複雜的應用程序,也許有些事情你可以做(重構代碼)來簡化它? –
這是一個3d應用程序,所以它是合法的,有一個相當廣泛和複雜的應用程序 –
是的的確,但添加一個簡單的布爾值不應該太難。即使你有一個複雜的應用程序,你仍然可以擁有乾淨的代碼。 –