何在没有hadoop安装的情况下在本地文件系统中创建hadoop

何在没有hadoop安装的情况下在本地文件系统中创建hadoop

本文介绍了如何在没有hadoop安装的情况下在本地文件系统中创建hadoop序列文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不安装hadoop的情况下从java创建hadoop序列文件?我需要一个在本地创建序列文件的独立Java程序。我的Java程序将运行在没有安装hadoop的env中。 你需要库而不是安装。使用

代码:

  import java.io.IOException; 
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.fs.FileSystem;
导入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自动生成的方法存根
配置config = new配置();
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();
}

}


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.

解决方案

You would need the libraries but not the installation. Use

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();
    }

}

这篇关于如何在没有hadoop安装的情况下在本地文件系统中创建hadoop序列文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 16:21