package com.hadoop.hdfs; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; public class Client { public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException { //1. 获取fs对象 Configuration conf=new Configuration(); FileSystem fs=FileSystem.get(new URI("hdfs://localhost:9000"),conf,"root"); //2. 执行上传API fs.copyFromLocalFile(new Path("e:/example.txt"),new Path("/example.txt")); //3.关闭资源 fs.close(); System.out.println("over"); } }