首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SequenceFile到.txt的转换

SequenceFile到.txt的转换
EN

Stack Overflow用户
提问于 2012-05-29 09:47:14
回答 1查看 6.2K关注 0票数 1

有没有办法把序列文件转换成.txt文件?这个序列文件是在一个hadoop作业之后生成的,当我尝试使用SequenceFileReader读取它时,它会给我一个EOFException,尽管作业已经成功完成。因此,我认为我可以将序列文件复制到我的本地系统,然后在可能的情况下转换为txt格式。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-29 20:29:25

将文件从seq更改为text不是查看issue..and的合适的solution..try,您可以尝试类似这样的内容来读取键/值对-

代码语言:javascript
复制
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文件转换为文本文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10792232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档