分享

SequenceFile

a2325145 发表于 2013-10-25 10:43:47 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 4532
大侠们问个
我写了个往HDFS上写文件,然后村委SequenceFile的格式,但是为什么写完之后到HDFS上查看发现还是原来的格式
public void writeToHdfs(String groupName,String writeFileName) throws IOException{
                 Configuration conf=new Configuration();
                 fs.setWorkingDirectory(new Path("/"));
                 boolean existFlag=fs.exists(new Path(groupName));
                 if(!existFlag) fs.mkdirs(new Path(groupName));
                 else
                         {System.out.println("thi directory existed!!");}
                 fs.setWorkingDirectory(new Path(groupName));
                 Path dstFile=new Path(writeFileName);
                 System.out.println("the current directory is: "+fs.getWorkingDirectory().toString());
                 
                 boolean existFileFlag=fs.exists(dstFile);
                 if(existFileFlag){
                         System.err.println(writeFileName+"is already exist!!!");
                         System.exit(-1);
                 }
                 
                 SequenceFile.Writer writer=null;
               
                 writer=SequenceFile.createWriter(fs, conf, dstFile, NullWritable.class, Text.class, SequenceFile.CompressionType.BLOCK);
                 BytesWritable value=new BytesWritable();
                 NullWritable key=NullWritable.get();
                 FileInputStream in =new FileInputStream(new File(writeFileName));
                 long length=in.available();
                 long time=System.currentTimeMillis();
                 while(length!=0){
                 System.out.println("1");
                 byte[] buf=new byte[4096];
                 in.read(buf);
                 System.out.println(buf[1]);
                 value.set(buf, 0, buf.length);
                 writer.append(key, value);
                 length-=buf.length;
                 
                 }
                 
                 long lasttime=System.currentTimeMillis();
                 System.out.println("the writtern time is: "+(lasttime-time));
                 IOUtils.closeStream(writer);
                 IOUtils.closeStream(in);
        }

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条