首页 > 其他 > 详细

使用idel和maven实现hadoop上数据的读取和写入

时间:2017-05-23 23:29:52      阅读:451      评论:0      收藏:0      [点我收藏+]
 1 public class TestRead {
 2     @Test
 3     public void readTest() throws Exception {
 4         Configuration conf = new Configuration();
 5         FileSystem fs = FileSystem.get(conf);
 6         FSDataInputStream fis = fs.open(new Path("hdfs://s201:8020/user/centos/hadoop/hello.txt"));
 7         IOUtils.copyBytes(fis, System.out, 1024);
 8         IOUtils.closeStream(fis);
 9 
10     }
11 
12     @Test
13     public void writeTest() throws Exception {
14         Configuration conf = new Configuration();
15         FileSystem fs = FileSystem.get(conf);
16         FSDataOutputStream fos = fs.create(new Path("hdfs://s201:8020/user/centos/hadoop/3.txt"),true,1024,(short)2,512);
17         ByteArrayInputStream bis=new ByteArrayInputStream("who am i".getBytes());
18         IOUtils.copyBytes(bis,fos,1024);
19         IOUtils.closeStream(fos);
20 
21     }
22 }

 

使用idel和maven实现hadoop上数据的读取和写入

原文:http://www.cnblogs.com/yihaifutai/p/6896607.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!