本文整理匯總了Java中org.apache.commons.io.FileUtils.contentEquals方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtils.contentEquals方法的具體用法?Java FileUtils.contentEquals怎麽用?Java FileUtils.contentEquals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.io.FileUtils
的用法示例。
在下文中一共展示了FileUtils.contentEquals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compare
import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
@Override
protected boolean compare(File baselineFile, File comparisonFile) {
try {
return FileUtils.contentEquals(baselineFile, comparisonFile);
} catch (IOException e) {
throw new TransformationUtilityException("An exception has happened when comparing files", e);
}
}
示例2: moveIfChanged
import org.apache.commons.io.FileUtils; //導入方法依賴的package包/類
private Report moveIfChanged(File root, String tmpPath) throws MojoFailureException, IOException {
Report report = new Report();
for (File file : root.listFiles()) {
if (file.isDirectory()) {
report.add(moveIfChanged(file, tmpPath));
if (!file.delete()) {
throw new MojoFailureException(format("can not delete %s", file));
}
} else {
String absPath = file.getAbsolutePath();
if (!absPath.startsWith(tmpPath)) {
throw new MojoFailureException(format("%s should start with %s", absPath, tmpPath));
}
String relPath = absPath.substring(tmpPath.length());
File outputFile = new File(output, relPath);
if (!outputFile.exists()) {
report.addNew();
} else if (!FileUtils.contentEquals(file, outputFile)) {
getLog().info(format("%s has changed", relPath));
if (!outputFile.delete()) {
throw new MojoFailureException(format("can not delete %s", outputFile));
}
report.addChanged();
} else {
report.addUnchanged();
}
if (!outputFile.exists()) {
File parentDir = outputFile.getParentFile();
if (parentDir.exists() && !parentDir.isDirectory()) {
throw new MojoFailureException(format("can not move %s to %s as %s is not a dir", file, outputFile, parentDir));
}
if (!parentDir.exists() && !parentDir.mkdirs()) {
throw new MojoFailureException(format("can not move %s to %s as dir %s can not be created", file, outputFile, parentDir));
}
FileUtils.moveFile(file, outputFile);
} else {
if (!file.delete()) {
throw new MojoFailureException(format("can not delete %s", file));
}
}
}
}
return report;
}