How to create hadoop sequence file in local file system without hadoop installation?

走远了吗. 提交于 2019-12-11 02:55:28

问题


Is it possible to create hadoop sequence file from java only without installing hadoop? I need a standalone java program that create sequence file locally. My java program will run in env that does not have hadoop install.


回答1:


You would need the libraries but not the installation. Use

SequenceFile.Writer

Sample code :

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
public class SequenceFileCreator {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        Configuration config = new Configuration();
        FileSystem fs = FileSystem.get(config);

        SequenceFile.Writer writer = new SequenceFile.Writer(fs, config, new Path("LocalPath"), NullWritable.class, Text.class);
        writer.append(NullWritable.get(), new Text(""));
        writer.close();
    }

}


来源:https://stackoverflow.com/questions/30256194/how-to-create-hadoop-sequence-file-in-local-file-system-without-hadoop-installat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!