码迷,mamicode.com
首页 > 其他好文 > 详细

Hadoop将本地文件复制到Hadoop文件系统

时间:2016-06-15 18:42:56      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

代码:

package com.hadoop;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Progressable;

public class FileCopyWithProgress {

	public static void main(String[] args) throws Exception {
		
		String localSrc = args[0];
		String dst = args[1];
		
		InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
		
		Configuration config = new Configuration();
		FileSystem fs = FileSystem.get(URI.create(dst),config);
		
		OutputStream out = fs.create(new Path(dst),new Progressable() {
			
			@Override
			public void progress() {
				System.out.println(".");
			}
		});
		
		IOUtils.copyBytes(in, out, 4096, true);
	}
}

  hadoop中执行:

技术分享

 

Hadoop将本地文件复制到Hadoop文件系统

标签:

原文地址:http://www.cnblogs.com/yixiwenwen/p/5588290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!