存入HDFS有好几种数据格式,我这里给你列出一种格式的存储,sequence的
public class SeqWrite {
private static final String[] data = { "a,b,c,d,e,f,g", "h,i,j,k,l,m,n", "o,p,q,r,s,t", "u,v,w,x,y,z", "0,1,2,3,4", "5,6,7,8,9" };
public static void main(String[] args) throws IOException, Exception {
Configuration configuration = new Configuration();
//这里是你主机的地址
configuration.set("fs.defaultFS", "192.168.51.140");
//这个是存储的路径
Path path = new Path("/tmp/test1.seq");
Option option = SequenceFile.Writer.file(path);
Option optKey = SequenceFile.Writer.keyClass(IntWritable.class);
Option optValue = SequenceFile.Writer.valueClass(Text.class);
SequenceFile.Writer writer = null;
IntWritable key = new IntWritable(10);
Text value = new Text();
writer = SequenceFile.createWriter(configuration, option, optKey, optValue);
for (int i = 0; i < data.length; i++) {
key.set(i);
value.set(data[i]);
writer.append(key, value);
writer.hsync();
Thread.sleep(10000L);
}
IOUtils.closeStream(writer);
}
}
创建对象 注入属性 在添加不就可以了