SequenceFile
大侠们问个我写了个往HDFS上写文件,然后村委SequenceFile的格式,但是为什么写完之后到HDFS上查看发现还是原来的格式
public void writeToHdfs(String groupName,String writeFileName) throws IOException{
Configuration conf=new Configuration();
fs.setWorkingDirectory(new Path("/"));
boolean existFlag=fs.exists(new Path(groupName));
if(!existFlag) fs.mkdirs(new Path(groupName));
else
{System.out.println("thi directory existed!!");}
fs.setWorkingDirectory(new Path(groupName));
Path dstFile=new Path(writeFileName);
System.out.println("the current directory is: "+fs.getWorkingDirectory().toString());
boolean existFileFlag=fs.exists(dstFile);
if(existFileFlag){
System.err.println(writeFileName+"is already exist!!!");
System.exit(-1);
}
SequenceFile.Writer writer=null;
writer=SequenceFile.createWriter(fs, conf, dstFile, NullWritable.class, Text.class, SequenceFile.CompressionType.BLOCK);
BytesWritable value=new BytesWritable();
NullWritable key=NullWritable.get();
FileInputStream in =new FileInputStream(new File(writeFileName));
long length=in.available();
long time=System.currentTimeMillis();
while(length!=0){
System.out.println("1");
byte[] buf=new byte;
in.read(buf);
System.out.println(buf);
value.set(buf, 0, buf.length);
writer.append(key, value);
length-=buf.length;
}
long lasttime=System.currentTimeMillis();
System.out.println("the writtern time is: "+(lasttime-time));
IOUtils.closeStream(writer);
IOUtils.closeStream(in);
}
页:
[1]