如何通过http请求获取远端Hadoop的文件数据

比如,朋友A要获取朋友B自己搭建的hdfs集群上的某个文件,ip和路径都知道,在不考虑安全认证什么的,如何通过http请求获取到,我查阅hadoop官网,发现有WebHdfsFileSystem支持http请求,但未找到java代码,哪位大腿有案例,麻烦给一个,谢谢

这个hdfs不是有web界面吗?默认端口号是50070,通过ip:50070就可以进入hdfs了,找对应路径下的文件下载即可,Java代码的话,教程参考如下

img

img

img

img


package java3.T16;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;


/*
 * URL:统一资源定位器(uniform resource locator)
 * */
public class URLDemo {

    public static void main(String[] args) {
        try {
            //方法1
            URL url1 = new URL("http://www.sms98.cn/images/weixin.jpg");
            //方法2
//            URL www = new URL("http://www.sms98.cn");
//            URL url2 = new URL(www,"index.html");
            //方法3
//            URL url3 = new URL("http","wwww.sms98.cn","index.html");
            //方法4
//            URL url4 = new URL("http","wwww.sms98.cn",80,"index.html");
            
            System.out.println(url1);
            URLConnection urlConn =  url1.openConnection();
            //获取输入流
            InputStream in = urlConn.getInputStream();
            //下载图片
            BufferedInputStream bis = new BufferedInputStream(in);
            //定义字节数组,循环读取文件内容
            byte b[] = new byte[2048];
            int len = 0;
            
            //定义输出流保存下载的文件
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("d:\\weixin.jpg"));
            //循环读取文件内容
            while((len=bis.read(b)) != -1) {
                //保存文件
                bos.write(b, 0, len);
            }
            bos.flush();
            bos.close();
            bis.close();
            System.out.println("文件下载成功。");
            
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


要的是JAVA.下载文件的代码?

都使用Java语言进行开发了,为啥还要使用WebHdfs,有些想不通。
WebHdfs 是提供给其他 非Java语言的 API。
如果楼主想要使用的话,自己使用HttpClient封装一个吧,Restful形式的交互,很简单的。