这个hdfs不是有web界面吗?默认端口号是50070,通过ip:50070就可以进入hdfs了,找对应路径下的文件下载即可,Java代码的话,教程参考如下
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形式的交互,很简单的。