码迷,mamicode.com
首页 > Web开发 > 详细

hadoop 上传文件

时间:2017-02-25 13:58:28      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:file   byte   on()   org   catch   ice   hadoop   .config   bytes   

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 UploadFile {
public static void main(String[] args) {
try {
String localSrc = "/usr/local/hadoop/NOTICE.txt";
String dst = "hdfs://localhost:9000/user/NOTICE.txt";
InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(dst), conf);
OutputStream out = fs.create(new Path(dst), new Progressable() {
public void progress() {
System.out.print(".");
}
});

IOUtils.copyBytes(in, out, 4096, true);

System.out.println("success");

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

 

 

hadoop 上传文件

标签:file   byte   on()   org   catch   ice   hadoop   .config   bytes   

原文地址:http://www.cnblogs.com/tk55/p/6441593.html

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