1. 程式人生 > >使用idel和maven實現hadoop上數據的讀取和寫入

使用idel和maven實現hadoop上數據的讀取和寫入

iou onf bytes 數據 fig pre cnblogs oop hello

 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上數據的讀取和寫入