通过FileSystem API访问读取HDFS数据
/**
* 通过FileSystem API访问读取HDFS数据
* $>hadoop fs -cat /spaceQuota/text.txt
* @throws IOException
*/
@Test
public void readByFS() throws IOException{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
String _path = "hdfs://master1:9000/spaceQuota/text.txt";
FSDataInputStream in = fs.open(new Path(_path));
IOUtils.copyBytes(in, System.out, 4096, true);
}
通过FileSystem API创建文件夹
/**
* 通过FileSystem API创建文件夹
* $>hadoop fs -mkdir /mkdir_byAPI
* 注意:修改集群权限:$>hadoo