Mahout中存在一个创建序列文件的命令bin/mahout seqdirectory -c UTF-8
-i <input address> -o <output address>
。我想使用此命令作为代码API。
答案 0 :(得分:3)
您可以这样做:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path outputPath = new Path("c:\\temp");
Text key = new Text(); // Example, this can be another type of class
Text value = new Text(); // Example, this can be another type of class
SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, outputPath, key.getClass(), value.getClass());
while(condition) {
key = Some text;
value = Some text;
writer.append(key, value);
}
writer.close();
此外,您可以使用org.apache.mahout.text.SequenceFilesFromDirectory
然后电话看起来像这样:
ToolRunner.run(new SequenceFilesFromDirectory(), String[] args //your parameters);
ToolRunner
来自org.apache.hadoop.util.ToolRunner
希望这有帮助。