gpt4 book ai didi

java - SequenceFile 到 .txt 转换

转载 作者:可可西里 更新时间:2023-11-01 15:41:28 26 4
gpt4 key购买 nike

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

最佳答案

将文件从 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 文件转换为文本文件...

关于java - SequenceFile 到 .txt 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10792232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com