1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| @Test public void putFile() throws IOException, URISyntaxException { System.setProperty("HADOOP_USER_NAME", "root"); Configuration conf=new Configuration(); FileSystem fs=FileSystem.get(new URI("hdfs://182.168.10.101:9820"),conf); FileInputStream input=new FileInputStream(new File("c://a.txt")); FSDataOutputStream out=fs.create(new Path("/gg.txt")); IOUtils.copyBytes(input, out, conf); IOUtils.closeStream(input); IOUtils.closeStream(out); System.out.println("上传完毕"); }
|