First, the priority code
Second, maven project's resource folder .xml configuration file
Third, modify server configuration
Fourth, the default configuration
Code modification example of the configuration
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.junit.Test; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; public class HDFSClientTest { @Test public void copyFromLocal() throws URISyntaxException, IOException, InterruptedException { Configuration conf = new Configuration(); conf.set("dfs.replication","2");//修改配置,设置副本数。 FileSystem fileSystem = FileSystem.get(new URI("hdfs://hadoop112:9000"), conf, "angel"); fileSystem.copyFromLocalFile(new Path("/home/angel/software/apache-maven-3.6.2-bin.tar.gz"),new Path("/")); fileSystem.close(); } }