本文整理汇总了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;
}