标签:客户端 1.0 对象 cal 总结 客户 ext replica tco
上传一个文件试试
public class ConfigPriority { private Configuration conf; private FileSystem fs; @Before public void init() throws Exception { // 设置 HADOOP_HOME 环境变量 System.setProperty("hadoop.home.dir", "D:/DevelopTools/hadoop-2.9.2/"); // 日志初始化 BasicConfigurator.configure(); conf = new Configuration(); // 获取 hdfs 客户端对象,指定用户名,避免无权限 fs = FileSystem.get(new URI("hdfs://192.168.8.136:9000"), conf, "root"); } @After public void close() throws IOException { fs.close(); } // 文件上传 @Test public void testCopyFromLocalFile() throws Exception{ fs.copyFromLocalFile(new Path("D://MyFile/Downloads/Writage-1.12.msi"), new Path("/Priority/AAA.msi")); } }
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>dfs.replication</name> <value>1</value> </property> </configuration>
代码中的上传名字做下改变
public class ConfigPriority { private Configuration conf; private FileSystem fs; @Before public void init() throws Exception { // 设置 HADOOP_HOME 环境变量 System.setProperty("hadoop.home.dir", "D:/DevelopTools/hadoop-2.9.2/"); // 日志初始化 BasicConfigurator.configure(); conf = new Configuration(); conf.set("dfs.replication","2"); // 获取 hdfs 客户端对象,指定用户名,避免无权限 fs = FileSystem.get(new URI("hdfs://192.168.8.136:9000"), conf, "root"); } @After public void close() throws IOException { fs.close(); } // 文件上传 @Test public void testCopyFromLocalFile() throws Exception{ fs.copyFromLocalFile(new Path("D://MyFile/Downloads/Writage-1.12.msi"), new Path("/Priority/CCC.msi")); } }
标签:客户端 1.0 对象 cal 总结 客户 ext replica tco
原文地址:https://www.cnblogs.com/jhxxb/p/10704806.html