将本地文件上传至HDFS

 //将本地文件上传到hdfs。
  String target="hdfs://localhost:9000/user/Administrator/geoway_portal/tes2.dmp";
  FileInputStream fis=new FileInputStream(new File("C:\\tes2.dmp"));//读取本地文件
  Configuration config=new Configuration();
  FileSystem fs=FileSystem.get(URI.create(target), config);
  OutputStream os=fs.create(new Path(target));
  //copy
  IOUtils.copyBytes(fis, os, 4096, true);
  System.out.println("拷贝完成...");

查看上传的hdfs的文件信息:

使用hadoop fs -ls shell命令查询geoway_portal下的文件情况:

原文地址:https://www.cnblogs.com/likehua/p/2759509.html