/**
成都创新互联服务项目包括港口网站建设、港口网站制作、港口网页制作以及港口网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,港口网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到港口省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
* 通过Hadoop api访问
* @throws IOException
*/
@Test
public void readFileByAPI() throws IOException{
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://192.168.75.201:8020/");
FileSystem fs = FileSystem.get(conf);
Path path = new Path("/user/index.html");
FSDataInputStream fis =fs.open(path);
byte[] bytes = new byte[1024];
int len = -1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while((len = fis.read(bytes))!=-1){
baos.write(bytes, 0, len);
}
System.out.println(new String(baos.toByteArray()));
fis.close();
baos.close();
}
第二种方式:
/**
* 通过hadoop api访问
* @throws IOException
*/
@Test
public void readFileByAPI2() throws IOException{
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://192.168.75.201:8020/");
FileSystem fs = FileSystem.get(conf);
Path path = new Path("/user/index.html");
FSDataInputStream fis =fs.open(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyBytes(fis, baos, 1024);
System.out.println(new String(baos.toByteArray()));
fis.close();
baos.close();
}
分享文章:通过hadoopAPI访问文件
本文来源:https://www.cdcxhl.com/article4/ijsjie.html
成都网站建设公司_创新互联,为您提供网页设计公司、电子商务、用户体验、品牌网站设计、网站改版、网站设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联