我刚刚发现这一点位二进制你对谷歌比较法,没有答应,如果它的工作原理;)
/**
* 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应用程序,所以它是合法的,有一个相当广泛和复杂的应用程序 –
是的的确,但添加一个简单的布尔值不应该太难。即使你有一个复杂的应用程序,你仍然可以拥有干净的代码。 –