文章目录
/**
* 上传
*/
@Test
public void putHDFS() throws IOException, URISyntaxException, InterruptedException {
//创建配置信息
Configuration conf = new Configuration();
//设置部分的临时参数
conf.set("dfs.replication", "2");
//获取文件系统
FileSystem fs = FileSystem.get(new URI("hdfs://bigdata121:9000"), conf, "root");
//要上传的本地文件上传的路径
Path input = new Path("F:\\input\\word.txt");
//输出的路径,iput复制到output
Path output = new Path("hdfs://bigdata121:9000/word.txt");
//以拷贝的方式
fs.copyFromLocalFile(input, output);
fs.close();
System.out.println("上传成功!!");
}
报错:
java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray.
网上找了个资源,
https://github.com/steveloughran/winutils 我用的是hadoop2.8.4 但是我选择替换的是hadoop.dll是
下面的
https://github.com/steveloughran/winutils/blob/master/hadoop-2.8.1/hadoop.dll 吧他放在
- 1.hadoop_hom/bin下
- 2.放在C:\Windows\System32下
然后运行:
大功告成!!!