hadoop hdfs基本命令的java编码实现

一、向hdfs上上传文件

首先需要进行配置文件的配置

Configuration conf = new Configuration();

 

//进行conf的设置

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

 

//通过配置文件得到fs的实例

FileSystem fs = FileSystem.get(conf);

 

//通过fs中封装的方法实现相应的需求

//创建一个保存文件的路径

Path destFile = new Path("hdfs:/hadoop01:9000/jdk.tgz");
FSDataOutputStream os = fs.create(destFile);

//配置上传文件的所在路径
FileInputStream is = new FileInputStream("/home/hadoopk-7u65-linux-i586.tar.gz");

//通过IO流的操作将所需上传的文件写到指定的fs路径下
IOUtils.copy(is, os); 
posted @ 2017-02-08 11:45  struggle&小白  阅读(1183)  评论(0编辑  收藏  举报