在我的石英作业中,我想使用 commons-vfs 从目录中读取 csv 文件。
try {
FileSystemManager fsManager = VFS.getManager();
final FileObject fileObject = fsManager.resolveFile(getJob().getDirectory());
if(fileObject.getType() != FileType.FOLDER) {
throw new FileTransferException("Invalid directory : " + getJob().getDirectory());
}
final FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(FileSelectInfo fileInfo) {
try {
boolean isCSV = fileInfo.getFile().getName().getBaseName().endsWith(".csv");
logger.debug("TEST : {} {} " + fileInfo.getFile().getName(), fileInfo.getFile().getType() , isCSV);
long fileTime = fileInfo.getFile().getContent().getLastModifiedTime();
return isCSV;
} catch (FileSystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
};
FileSelector selector = new FileFilterSelector(fileFilter);
FileObject[] findFiles = fileObject.findFiles(selector);
for (int i = 0; i < findFiles.length; i++) {
logger.info("Found {} : {}", i, findFiles[i]);
}
} catch(Exception e) {
throw new JobExecutionException(e);
}
文件夹中有一些文件,但是当我想检查文件日期并过滤太旧的文件时会引发异常。它还显示奇怪的“虚构”作为文件类型 - 它是真实文件,它自己刚刚找到它:
18:13:27.807 DEBUG [AE-Scheduler_Worker-2][CsvImportJob]
TEST : imaginary false file:///e:/some_directory /not_csv.txt
org.apache.commons.vfs2.FileSystemException: Could not determine the last modified timestamp of "file:///e:/some_directory /not_csv.txt" because it does not exist.
at org.apache.commons.vfs2.provider.DefaultFileContent.getLastModifiedTime(DefaultFileContent.java:165)
我做错了什么?