hadoop java API实现文件下载

package com.zlf;

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Demo {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        Configuration conf=new Configuration();

        conf.set("fs.defaultFS", "hdfs://localhost:9000");

        FileSystem fs=FileSystem.get(conf);

        FSDataInputStream fsDataInputStream=fs.open(new Path("/RoseHA.rar"));

        FileOutputStream fileOutputStream=new FileOutputStream("e:/RoseHA.rar");

        IOUtils.copy(fsDataInputStream, fileOutputStream);


    }

}

下面是另一种实现方式,非常简单。

fs.copyToLocalFile(new Path("/PowerDesigner15_Evaluation.rar"), new Path("e:/PowerDesigner15_Evaluation.rar"));

你可能感兴趣的:(hadoop)