【发布时间】:2014-01-29 13:39:02
【问题描述】:
我正在处理一段代码,我需要处理位于使用 Apache camel 的服务器上的文件。我需要实现以下步骤:
1 --> 控件应该遍历位于特定文件夹中的所有文件。
2 --> 然后它应该检查哪个文件超过 15 天。
3 --> 然后删除超过 15 天的文件。
现在,我可以实现第一步和第二步了。但我无法删除该文件。 我创建了这样的骆驼路线:
<camel:route id="lastModifiedFMFileCheckRoute">
<camel:from uri="sftp://someUser@someServer/usableFiles?password=secret"/>
<camel:setProperty propertyName="availableFile">
<camel:simple>${body}</camel:simple>
</camel:setProperty>
<camel:process ref="fileModificationDateProcessor" />
</camel:route>
我的处理器的处理方法看起来像这样,我正在检查文件是否超过 15 天。
@Override
public void process(Exchange exchange) throws Exception {
boolean isFileDeleted = false;
@SuppressWarnings("rawtypes")
GenericFile currentFile = (GenericFile)exchange.getProperty("availableFile", RemoteFile.class);
Date currentDate = new Date();
int numberOfDays = (int)( (currentDate.getTime() - availableFile.getLastModified()) / MILLISECONDS_TO_DAY_CONVERTER_VALUE);
if(numberOfDays > 15){
String absoluteFilePath = availableFile.getAbsoluteFilePath();
//TODO The file (currentFile) needs to be deleted. As it is older than 15 days.
}
exchange.getOut().setBody(fileDeleted);
}
这里如何实现所需文件的删除。
【问题讨论】:
标签: java ftp apache-camel sftp