hdfs的相关api
连接hdfs
根据hdfs的版本引用相关的hdfs依赖
org.apache.hadoop
hadoop-client
2.6.5
org.apache.hadoop
hadoop-common
2.6.5
org.apache.hadoop
hadoop-hdfs
2.6.5
将hdfs中的core-site.xml
和hdfs-site.xml
放进项目的resources目录里
简单编码测试下
public class Connection {
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
Configuration configuration=new Configuration();
System.setProperty("HADOOP_USER_NAME", "root");
FileSystem fs = FileSystem.get(configuration);
System.out.println(fs.getHomeDirectory());
//拿到FileSystem后可以简单操作下hdfs,若是运行成功则代表连接成功!
}
}
原文:https://www.cnblogs.com/shouyaya/p/14130657.html