Hadoop 本地文件复制到hdfs目录

2019-03-28 13:28|来源: 网络

Hadoop 本地文件复制到hdfs目录

  1. public static void main(String[] args) throws Exception {   
  2.         String localSrc = "/home/ganliang/test_fileCopyWithProgress.txt";//本地文件   
  3.         String dst = "hdfs://localhost:9000/user/ganliang/hadoop_in/test_fileCopyWithProgress.txt";//复制到hdfs目录下   
  4.         InputStream in = new BufferedInputStream(new FileInputStream(localSrc));   
  5.         Configuration conf = new Configuration();   
  6.         FileSystem fs = FileSystem.get(URI.create(dst), conf);   
  7.         OutputStream out = fs.create(new Path(dst), new Progressable() {//进度条信息   
  8.             public void progress() {   
  9.                 System.out.print(".");   
  10.             }   
  11.         });   
  12.         IOUtils.copyBytes(in, out, 4096true);//复制   
  13.     }  

相关问答

更多