/*********************************************************************
* 版权信息:博睿宏远科技发展有限公司
* Copyright: Copyright (c) 2007博睿宏远科技发展有限公司,Inc.All Rights Reserved.
* @date ${date}
* @Author: 徐昌
* Description:hadoop文件读取
********************************************************************/
public class HadoopRead {
//根据URL读取数据
public void readUrl() {
InputStream in = null;
try {
in = new URL("hdfs://host/path").openStream();
//按照文件流的方式处理读取的数据
} catch (Exception e) {
}
}
//根据FileSystem API
public void read() throws IOException {
String url = "hdfs://host/path";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(url), conf);
InputStream in = null;
in = fs.open(new Path(url));
IOUtils.copyBytes(in, System.out, 4096, false);
IOUtils.closeStream(in);
}
}