【问题标题】:HDFS has file but java.io.FileNotFoundException happensHDFS 有文件但发生 java.io.FileNotFoundException
【发布时间】:2015-04-01 10:33:16
【问题描述】:

我在 Hadoop 上运行 MapReduce 程序。

输入格式将每个文件路径传递给映射器。

我可以像这样通过cmd查看文件,

$ hadoop fs -ls hdfs://slave1.kdars.com:8020/user/hadoop/num_5/13.pdf

找到 1 项 -rwxrwxrwx 3 hdfs hdfs 184269 2015-03-31 22:50 hdfs://slave1.kdars.com:8020/user/hadoop/num_5/13.pdf

但是,当我尝试从映射器端打开该文件时,它不起作用。

15/04/01 06:13:04 信息 mapreduce.Job:任务 ID:尝试_1427882384950_0025_m_000002_2,状态:失败 错误:java.io.FileNotFoundException: hdfs:/slave1.kdars.com:8020/user/hadoop/num_5/13.pdf(没有这样的文件或目录)

at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1111)

我检查了 inputformat 工作正常并且映射器有正确的文件路径。 映射器代码如下所示,

@Override
public void map(Text title, Text file, Context context) throws IOException, InterruptedException {

    long time = System.currentTimeMillis(); 
    SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    String str = dayTime.format(new Date(time));

    File temp = new File(file.toString());
    if(temp.exists()){
        DBManager.getInstance().insertSQL("insert into `plagiarismdb`.`workflow` (`type`) value ('"+temp+" is exists')");
    }else{
        DBManager.getInstance().insertSQL("insert into `plagiarismdb`.`workflow` (`type`) value ('"+temp+" is not exists')");
    }
}

请帮帮我。

【问题讨论】:

    标签: hadoop


    【解决方案1】:

    首先,导入这些。

    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    

    然后,在您的映射器方法中使用它们。

    FileSystem fs = FileSystem.get(new Configuration());
    
    Path path=  new Path(value.toString());
    System.out.println(path);
    
    if (fs.exists(path)) {
        context.write(value, one);
    } else {
        context.write(value, zero);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 2022-01-10
      • 2012-07-18
      • 2014-11-27
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      相关资源
      最近更新 更多