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/19015405