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); 
原文地址:https://www.cnblogs.com/xzdblogs/p/6377514.html