栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 前沿技术 > 云计算 > 云平台

第二十七讲.动态设置相关参数(replication为2和blocksize为10字节)

云平台 更新时间:发布时间: 百科书网 趣学号

视频:【美妙人生】Hadoop课程系列之HDFS–手把手教你精通HDFS

【美妙人生】Hadoop课程系列之HDFS–手把手教你精通HDFS

【视频笔记】


通过java.net.URL类访问写入HDFS数据
----------------------------------------------------------------

?? ?
?? ?@Test
?? ?public void writeByURL() throws Exception {
?? ??? ?URL _url ?=new URL("hdfs://master1:9000/spaceQuota/hello.txt");
?? ??? ?URLConnection conn = _url.openConnection();
?? ??? ?OutputStream out = conn.getOutputStream();
?? ??? ?out.write("hello world".getBytes());
?? ??? ?out.close();
?? ?} ? ?

通过FileSystem API做write操作
----------------------------------------------------------------------------

? ?
?? ?@Test
?? ?public void ?writeByAPI() throws IOException{
?? ??? ?Configuration conf = new Configuration();
?? ??? ?FileSystem fs ?=FileSystem.get(conf);
?? ??? ?Path file = new Path("/spaceQuota/hello.txt");
?? ??? ?FSDataOutputStream out = fs.create(file);
?? ??? ?out.write("hello world".getBytes());
?? ??? ?out.close();
?? ?}

通过FileSystem API做写操作,动态设置相关参数:replication为2和blocksize为10字节
-----------------------------------------------------------------------------------------------

 ?
?? ?@Test
?? ?public void writeByAPIForBlocksize() throws IOException{
?? ??? ?Configuration conf = new Configuration();
?? ??? ?conf.set("fs.defaultFS", "hdfs://master1:9000");
?? ??? ?conf.set("dfs.bytes-per-checksum", "10");
?? ??? ?FileSystem fs ?=FileSystem.get(conf);
?? ??? ?Path file = new Path("/spaceQuota/hello6666.txt");
?? ??? ?FSDataOutputStream out = fs.create(file, true, 4096,(short)2, 10);
?? ??? ?out.write("hello world".getBytes());
?? ??? ?out.close();
?? ?}
转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/1072994.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号