Java读SequenceFile

来源:互联网 发布:vb集成开发环境功能 编辑:程序博客网 时间:2024/06/07 11:38

 protected void setup(Context context)
   throws IOException, InterruptedException {
  super.setup(context);
  
  interestfile = context.getConfiguration().get("interestfile");
        Configuration conf = new Configuration();
        SequenceFile.Reader sfr = null;
        try {
            FileSystem fs = FileSystem.get(URI.create(interestfile), conf);
            try {

                sfr = new SequenceFile.Reader(fs, new Path(interestfile), conf);
                Writable k = (Writable) ReflectionUtils.newInstance(sfr.getKeyClass(), conf);
                Writable v = (Writable) ReflectionUtils.newInstance(sfr.getValueClass(), conf);
                while (sfr.next(k, v)) {
                    userCate.put(k.toString(),v.toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                IOUtils.closeStream(sfr);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
  
 }

原创粉丝点击