hadoop打包上传报:Wrong FS: hdfs://localhost:9000/user/hadoop, expected: file:///
//1、获取文件系统
Configuration con = new Configuration();
//2、连接集群
con.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
Path path = new Path("hdfs://bigdata01:9000/lesson/20200122031733.txt");
FileSystem fileSystem = path.getFileSystem(con);
//3、把本地文件上传到文件系统
fileSystem.copyFromLocalFile(new Path("/opt/soft/20200122031733.txt"),new Path("hdfs://bigdata01:9000/lesson/20200122031733.txt"));
//4、关闭资源
fileSystem.close();
System.out.println("上传成功");
与本地文件对比
//1、获取文件系统
Configuration con = new Configuration();
//2、连接集群
con.set("fs.defaultFS","hdfs://bigdata01:9000");
FileSystem fileSystem = FileSystem.get(con);
//3、把本地文件上传到文件系统
fileSystem.copyFromLocalFile(new Path("F:\\jdk.docx"),new Path("/jdk.docx"));
//4、关闭资源
fileSystem.close();
System.out.println("上传成功");