hadoop HDFS工具类---对hdfs的读、写


1、文件流写入hdfs

 public static void putFileToHadoop(String hadoop_path, byte[] fileBytes)	throws Exception {
 
  Configuration conf = new Configuration();
  FileSystem fs = FileSystem.get(URI.create(hadoop_path), conf);
  Path path = new Path(hadoop_path);
  FSDataOutputStream out = fs.create(path);
  // 控制复本数量-wt
  fs.setReplication(path, (short) 1);
  out.write(fileBytes);
  out.close();
 }

如何获取文件流可以参考http://blog.csdn.net/smile0198/article/details/19015027

相关内容