有没有办法把序列文件转换成.txt文件?这个序列文件是在一个hadoop作业之后生成的,当我尝试使用SequenceFileReader读取它时,它会给我一个EOFException,尽管作业已经成功完成。因此,我认为我可以将序列文件复制到我的本地系统,然后在可能的情况下转换为txt格式。
发布于 2012-05-29 20:29:25
将文件从seq更改为text不是查看issue..and的合适的solution..try,您可以尝试类似这样的内容来读取键/值对-
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文件转换为文本文件。
https://stackoverflow.com/questions/10792232
复制相似问题