使用实例:
1.项目结构(引入包hadoop-0.20.2-core.jar和commons-logging.jar)
2.代码
HdfsCommon.java
public class HdfsCommon {
private Configuration conf;
private FileSystem fs;
public HdfsCommon() throws IOException{
conf=new Configuration();
fs=FileSystem.get(conf);
}
/**
* 上传文件,
* @param localFile 本地路径
* @param hdfsPath 格式为hdfs://ip:port/destination
* @throws IOException
*/
public void upFile(String localFile,String hdfsPath) throws IOException{
InputStream in=new BufferedInputStream(new FileInputStream(localFile));
OutputStream out=fs.create(new Path(hdfsPath));
IOUtils.copyBytes(in, out, conf);
}
/**
* 附加文件
* @param localFile
* @param hdfsPath
* @throws IOException
*/
public void appendFile(String localFile,String h