對於java自動化而言我是新手,我有一個需要導航到特定文件夾的場景,文件夾中有我需要的文件列表按日期過濾並獲取最近生成的文件名,即如果當前時間是下午5:30,我需要找到在下午5:28到當前時間(下午5:30)之間創建的文件名稱如何使用Java代碼從具有當前日期和時間的文件夾中獲取文件名
這必須是使用Java代碼,文件名的文件夾 DOF_US_DELL_1.0_20160930_0516.CSV
DOF_US_DELL_1.0_20160930_0756.CSV在
DOF_US_DELL_1.0_20161003_0346.CSV
DOF_實現US_DELL_1.0_20161003_0536.CSV
DOF_US_DELL_1.0_20161004_0747.CSV
DOF_US_DELL_1.0_20161005_0527.CSV
下面是一段代碼,可以幫助我獲取的文件列表中的目錄中
File dir = new File("C:\\FolderName");
FilenameFilter filter = new FilenameFilter() {
public boolean accept
(File dir, String name) {
return name.startsWith("DOF");
}
};
String[] children = dir.list(filter);
if (children == null) {
System.out.println("Either dir does not exist or is not a directory");
}
else
{
System.out.println("# of the files in the folder is: "+children.length);
if(children.length>0)
{
for (int i=0; i<children.length; i++)
{
String filename = children[i];
System.out.println(filename);
}
}
else
{
System.err.println("# of the files in the folder is: "+children.length);
fail("# of the files in the folder is: "+children.length);
}
}
謝謝提前。
祝你好運。也許如果你向我們展示你試圖在你的問題中編碼,我們可能會給你更具體的幫助。 –
嗨吉爾伯特感謝您的回覆...我已編輯我原來的帖子,請檢查出你是否可以幫助我.... –