HDFS 有文件但发生 java.io.FileNotFoundException

HDFS has file but java.io.FileNotFoundException happens

我是 运行 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:attempt_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)

我检查过输入格式工作正常并且映射器有正确的文件路径。 映射器代码如下所示,

@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')");
    }
}

请帮帮我。

首先,导入这些。

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);
}