1

有没有办法将序列文件转换为 .txt 文件?序列文件是在一个hadoop作业之后生成的,当我尝试使用SequenceFileReader读取它时,它给了我一个EOFException,尽管该作业成功完成。所以我虽然可以将序列文件复制到我的本地系统,然后尽可能转换为 txt 格式。

4

1 回答 1

1

将文件从 seq 更改为 text 不是一个合适的解决方案..尝试查看问题..您可以尝试类似的方法来读取键/值对 -

public class SequenceFileReader {
    public static void main(String args[]) throws Exception {
        System.out.println("Readeing Sequence File");
        Configuration conf = new Configuration();
        conf.addResource(new Path("/home/mohammad/hadoop-0.20.203.0/conf/core-site.xml"));
        conf.addResource(new Path("/home/mohammad/hadoop-0.20.203.0/conf/hdfs-site.xml"));  
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path("/seq/file");
        SequenceFile.Reader reader = null;      
        try {
            reader = new SequenceFile.Reader(fs, path, conf);
            Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
            Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
            while (reader.next(key, value)) {
                System.out.println(key + "  <===>  " + value.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeStream(reader);
        }
    }
}

您可以使用“hadoop fs -text seqfile”命令将 seq 文件转换为文本文件...

于 2012-05-29T12:29:24.637 回答