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