import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @RestController public class HadoopFileController { @RequestMapping("/hadoop") public void hadoop() throws URISyntaxException, IOException, InterruptedException { Configuration conf = new Configuration(); //指定客服端上传hdfs上传副本数为2 // conf.set("dfs.replication","2"); // conf.set("dfs.blocksize","64m"); FileSystem fs= FileSystem.get(new URI("hdfs://192.168.96.130:9000/"),conf,"root"); fs.mkdirs(new Path("/xx/yy/zz")); fs.close(); } }
Java操作HDFS
最新推荐文章于 2023-12-01 17:21:31 发布