我有下面的代码,我正在从特定目录读取文件,处理它,一旦处理,我将文件移动到存档目录。这工作正常。我每天都会收到新文件,并且我正在使用 Control-M 调度程序作业来运行此过程。
现在在下一次运行中,我再次从该特定目录中读取新文件,并使用存档目录中的文件检查该文件,如果内容不同,则仅处理该文件,否则不执行任何操作。编写了 shell 脚本来完成这项工作,我们没有看到这个过程的任何日志。
现在,如果文件与特定目录和存档目录中的文件相同,我想在我的 java 代码中生成日志消息,然后生成“文件相同”的日志。但我不知道该怎么做。我不想编写逻辑来处理或移动文件中的任何内容..我只需要检查文件是否相等,如果是则生成日志消息。我收到的文件不是很大,最大可以到 10MB。
下面是我的代码:
for(Path inputFile : pathsToProcess) {
// read in the file:
readFile(inputFile.toAbsolutePath().toString());
// move the file away into the archive:
Path archiveDir = Paths.get(applicationContext.getEnvironment().getProperty(".archive.dir"));
Files.move(inputFile, archiveDir.resolve(inputFile.getFileName()),StandardCopyOption.REPLACE_EXISTING);
}
return true;
}
private void readFile(String inputFile) throws IOException, FileNotFoundException {
log.info("Import " + inputFile);
try (InputStream is = new FileInputStream(inputFile);
Reader underlyingReader = inputFile.endsWith("gz")
? new InputStreamReader(new GZIPInputStream(is), DEFAULT_CHARSET)
: new InputStreamReader(is, DEFAULT_CHARSET);
BufferedReader reader = new BufferedReader(underlyingReader)) {
if (isPxFile(inputFile)) {
Importer.processField(reader, tablenameFromFilename(inputFile));
} else {
Importer.processFile(reader, tablenameFromFilename(inputFile));
}
}
log.info("Import Complete");
}
}