AnsweredAssumed Answered

How to add read file method in mapreduce ?

Question asked by hadoop23 on Nov 13, 2013
Latest reply on Nov 13, 2013 by Ted Dunning
Here is my readfile method :

    public void readFile(String file) throws IOException{
            Configuration conf = new Configuration();
    
        conf.addResource(new Path("/etc/hadoop/conf.empty/core-site.xml"));
        conf.addResource(new Path("/etc/hadoop/conf.empty/hdfs-site.xml"));
            FileSystem fileSystem = FileSystem.get(conf);
    
        Path path = new Path("hdfs://hdpmaster.agiledc.lab:8020/user/hadoop1/input/alchemist.pdf");
        
        if (!fileSystem.exists(path)) {
            System.out.println("File does not exists");
            return;
        }
    
        FSDataInputStream in = fileSystem.open(path);
    
        /*String filename = file.substring(file.lastIndexOf('/') + 1,
            file.length());*/
    
        OutputStream out = new BufferedOutputStream(new FileOutputStream(
            new File("hdfs://hdpmaster.agiledc.lab:8020/user/hadoop1/output")));
    
        byte[] b = new byte[1024];
        int numBytes = 0;
        while ((numBytes = in.read(b)) > 0) {
            out.write(b, 0, numBytes);
        }
    
        in.close();
        out.close();
        fileSystem.close();
    }

Outcomes