MapReduce之SequenceFile转普通文件

xiaoxiao2021-02-28  93

package com.uplooking.bigdata.mr.writablez.sequecefile; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.SequenceFile; import org.apache.hadoop.io.SequenceFile.Reader; import org.apache.hadoop.io.SequenceFile.Reader.Option; import org.apache.hadoop.io.Text; import java.io.*; /**  * 将一个SequenceFile的文件转变成为一个普通的文本文件  */ public class SequenceFileReadOps {     public static void main(String[] args) throws Exception {         if(args == null || args.length < 2) {             System.err.println("Parameter Errors ! Usage: <inputpath outputpath>");             System.exit(-1);         }         String inputpath = args[0]; //        Path outputpath = new Path(args[1]);         String outputpath = args[1];         Configuration conf = new Configuration();         Option inputOps = Reader.file(new Path(inputpath));         Option[] opts = new Option[]{inputOps};         Reader reader = new SequenceFile.Reader(conf, opts);         Text key = new Text();         BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));         while(reader.next(key, NullWritable.get())) {//将数据写入到key里面了             String line = key.toString();             bw.write(line);             bw.newLine();         }         bw.close();         reader.close();     } }
转载请注明原文地址: https://www.6miu.com/read-71599.html

最新回复(0)