public static void wrteFileHdfs(String localSrc,String hdfsPath){
try {
InputStream in=new BufferedInputStream(new FileInputStream(localSrc));
Configuration conf=new Configuration();
FileSystem fs=FileSystem.get(URI.create(hdfsPath), conf);
OutputStream out=fs.create(new Path(hdfsPath), new Progressable(){
@Override
public void progress() {
System.out.println("*");
}
});
IOUtils.copyBytes(in, out, 4096,true);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String localSrc="/home/zkpk/sogou100.txt";
String hdfsPath="hdfs://master:9000/search/";
WriteHdfsFile.wrteFileHdfs(localSrc, hdfsPath);
}