`
qingwei201314
  • 浏览: 168210 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Java操作HDFS

 
阅读更多
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();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics