java从hdfs中下载文件到本地
2017-08-15 14:10
218 查看
hdfs 在linux 搭建好,之后启动hdfs
hdfs核心机制看可这 篇
http://www.cnblogs.com/thinkpad/p/5173705.html
接下来新建java项目 引入HDFS所需要的包,这里的jar包可以从hadoop安装包里拿
解压haddoop gz进入 hadoop-2.4.1\share\hadoop\hdfs
进入hadoop-2.4.1\share\hadoop\common
导入java项目 编写如下demo
首先你现在的东西在hdfs上是有的
conf配置文件从etc/hadoop/拿。
core-site.xml
hafs-site.xml
放到src目录下
运行,查看F://aa.txt文件
hdfs核心机制看可这 篇
http://www.cnblogs.com/thinkpad/p/5173705.html
接下来新建java项目 引入HDFS所需要的包,这里的jar包可以从hadoop安装包里拿
解压haddoop gz进入 hadoop-2.4.1\share\hadoop\hdfs
进入hadoop-2.4.1\share\hadoop\common
导入java项目 编写如下demo
package hdfs.zanghan; 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 HdfsUtils { public static void main(String[] args) throws IOException { //上传文件到HDFS Configuration conf=new Configuration(); FileSystem fs=FileSystem.get(conf); Path src=new Path("hdfs://zanghan02:9000/aa.txt"); FSDataInputStream inputStream=fs.open(src); FileOutputStream os=new FileOutputStream("F://aa.txt"); IOUtils.copy(inputStream,os); } }
首先你现在的东西在hdfs上是有的
conf配置文件从etc/hadoop/拿。
core-site.xml
hafs-site.xml
放到src目录下
运行,查看F://aa.txt文件
相关文章推荐
- [Java教程]从HDFS下载文件到本地
- java实现将hdfs上的文件下载到本地系统上
- 用java 代码下载Samba服务器上的文件到本地目录以及上传本地文件到Samba服务器
- java 把已知下载路径的文件复制到本地
- hdfs下载文件到本地
- java 下载文件到本地,输出样式 header('Content-Type:application/xxx')
- java下载远程http地址的图片文件到本地-自动处理图片是否经过服务器gzip压缩的问题
- java实现网上下载文件到本地
- JAVA通过访问页面中的URL实现Http文件下载到本地
- JAVA 实现通过URL下载文件到本地库
- hadoop生态系统学习之路(三)java实现上传文件(本地或ftp)至hdfs
- java 下载本地文件 下载网络文件
- java 中 excel生成并文件下载保存到本地(三)
- Java 使用urlconnection下载文件或图片并保存到本地
- JAVA实现:将文件从本地上传到HDFS上、从HDFS上读取等操作
- 下载网络文件 与 java得到本地目录文件对象
- (2-4)HDFS的Java接口,上传,下载,创建文件,删除文件
- JAVA下载TXT文件到本地,这一个方法完全能够解决
- java本地文件下载
- <实战> 用java 代码下载Samba服务器上的文件到本地目录以及上传本地文件到Samba服务器 推荐