写入数据
FileSystem的创建文件的两个方法:create()和append()
package com.digitalchina.test;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.URI;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IOUtils;import org.apache.hadoop.util.Progressable;public class HadoopUrl {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubString localSrc="";String dst=""; InputStream in=null;OutputStream out=null;try {in=new BufferedInputStream(new FileInputStream(localSrc));Configuration conf=new Configuration();FileSystem fs=FileSystem.get(URI.create(dst), conf);out=fs.create(new Path(dst), new Progressable(){@Overridepublic void progress() {// TODO Auto-generated method stubSystem.out.println(".");}});IOUtils.copyBytes(in, out, conf, false);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{IOUtils.closeStream(out);IOUtils.closeStream(in);}}}