有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在两个日期之间从HDFS提取文件

我希望提取两个日期之间存储在HDFS中的所有文件。例如,用户选择StartDate和EndDate返回在这两个日期之间创建的文件

如下例:如果选择10-11-1984和02-01-2020,则应返回两个文件:file3.txtfile4.txt

/folder_1/file1.txt  24-20-2021
/folder_1/file2.txt  02-10-2020
/folder_1/file3.txt  10-11-1984
/folder_1/file4.txt  02-01-2020

我有一个函数返回JSON格式的数据,如本例所示:https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/WebHDFS.html#List_a_Directory

我做了一个新函数,只取"modificationTime"

public String getmodificationTime(String hdfsPath) 
    {
        
        if(hdfs!=null)
        {
            try
            {
                Path HdfsPath = new Path(hdfsPath);
                FileStatus[] fileIter = this.hdfs.listStatus(HdfsPath);
                
                for (int i=0;i<fileIter.length;i++)
                {
                    
                    String path = fileIter[i].getPath().toString(); 
                        
                    // get Modification time from listStatus
                    long modificationTimeLong = fileIter[i].getModificationTime();
                    Date modificationTimeDate = new Date(modificationTimeLong);
                    DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); //Example date format: Wed, 4 Jul 2001 12:08:56 -0700 from java doc
                    String dfDate = df.format(modificationTimeDate); 
                    System.out.println("The file '"+ path + "' was inserted at: "+ dfDate);
                    
                    
                }
            }
            catch(IOException e)
            {
                logger.error("Path: '{}' not exist", hdfsPath, e.getMessage());             
            }
            
        }
    return dfDate;

这里的问题是return语句,它不能接受返回变量dfDate:Suggestion:Create local variable dfDate / Create field dfDate / Create parameter dfDate / Create constant dfDate

你能给我一个解决方案吗?我如何在两个日期之间从HDFS中提取文件? 知道我找到了这个解决方案How to get the HDFS file data between 2 dates only in nifi workflow?

但是我认为hdfs.lastModified在HDFS客户机中是不受欢迎的


共 (0) 个答案