上传本地文件到hdfs

前提是安装配置好hadoop环境
java

1,命令上传

hdfs dfs -put /home/minst_svmlight.txt  /home/minst_svmlight.txtoop

                      本地文件                             hdfs上的路径spa

上传后的文件名并不必定和原先的同样。能够从新命名。
code

2,java代码上传实现

public static void fileUp() throws IOException {
		String target = "hdfs://master:9000/dataanalysis.jar";
		String local = "D:/Java/data-analysis.jar";
		FileInputStream in = new FileInputStream(new File(local));
		Configuration conf = new Configuration();
		FileSystem fs = FileSystem.get(URI.create(target), conf);
		OutputStream out = fs.create(new Path(target));
		IOUtils.copyBytes(in, out, 4096, true);
		log.info("上传完成。。。。。。。");
	}