获取hdfs文件系统对象
java操作hdfs,需要先获取到文件对象,执行url和用户名等,连接配置很多,需要实际项目需要时补充,基础可用的简单代码如下:
private static String hdfsPath = "hdfs://192.168.139.9:9000";
/**
* 获取HDFS文件系统对象
*
* @return
* @throws Exception
*/
private static FileSystem getFileSystem() throws Exception
{
FileSystem fileSystem = FileSystem.get(new URI(hdfsPath), getConfiguration(), "root");
return fileSystem;
}
/**
* 获取HDFS配置信息
*
* @return
*/
private static Configuration getConfiguration() {
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", hdfsPath);
return configuration;
}
java中hdfs基础的增删改查
连接上hdfs,获取到文件系统对象后,就可以进行相关的操作,如下所示:
/**
* 在HDFS创建文件夹
*
* @param