至HDFS附加内容
在最近的項(xiàng)目開(kāi)發(fā)中遇到的問(wèn)題:
需要產(chǎn)生良好hdfs文件的其他內(nèi)容。但使用在線(xiàn)版1.0.3。見(jiàn)發(fā)現(xiàn)官方文件,于1.0.4支持的文件的版本號(hào)之后append
一下是向hdfs中追加信息的操作方法
假設(shè)你僅僅在某一個(gè)driver中追加內(nèi)容信息。不必要對(duì)于整個(gè)HDFS都開(kāi)啟內(nèi)容追加:
在某個(gè)方法中。追加文件信息:
private void combinerMid(Path input,Path output,Configuration conf){
? ? ? ? ? ? FileSystem hdfs = null;
? ? ? ? ? ? conf.setBoolean("dfs.support.append", true);
? ? ? ? ? ? try{
? ? ? ? ? ? ? ? hdfs = FileSystem.get(conf);
? ? ? ? ? ? ? ? FSDataInputStream in = hdfs.open(input);
? ? ? ? ? ? ? ? FSDataOutputStream out = hdfs.append(output);
? ? ? ? ? ? ? ? IOUtils.copyBytes(in,out,4096,true);
? ? ? ? ? ? }catch (IOException e){
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
使用以上方法,便能夠向output文件里追加input中的文件內(nèi)容
假設(shè)須要開(kāi)啟對(duì)于整個(gè)HDFS的文件追加內(nèi)容權(quán)限須要在
hdfs-site.xml中添加下面配置
<property>
? ? <name>dfs.support.append</name>
? ? <value>true</value>
</property>
需要產(chǎn)生良好hdfs文件的其他內(nèi)容。但使用在線(xiàn)版1.0.3。見(jiàn)發(fā)現(xiàn)官方文件,于1.0.4支持的文件的版本號(hào)之后append
一下是向hdfs中追加信息的操作方法
假設(shè)你僅僅在某一個(gè)driver中追加內(nèi)容信息。不必要對(duì)于整個(gè)HDFS都開(kāi)啟內(nèi)容追加:
在某個(gè)方法中。追加文件信息:
private void combinerMid(Path input,Path output,Configuration conf){
? ? ? ? ? ? FileSystem hdfs = null;
? ? ? ? ? ? conf.setBoolean("dfs.support.append", true);
? ? ? ? ? ? try{
? ? ? ? ? ? ? ? hdfs = FileSystem.get(conf);
? ? ? ? ? ? ? ? FSDataInputStream in = hdfs.open(input);
? ? ? ? ? ? ? ? FSDataOutputStream out = hdfs.append(output);
? ? ? ? ? ? ? ? IOUtils.copyBytes(in,out,4096,true);
? ? ? ? ? ? }catch (IOException e){
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
使用以上方法,便能夠向output文件里追加input中的文件內(nèi)容
假設(shè)須要開(kāi)啟對(duì)于整個(gè)HDFS的文件追加內(nèi)容權(quán)限須要在
hdfs-site.xml中添加下面配置
<property>
? ? <name>dfs.support.append</name>
? ? <value>true</value>
</property>
版權(quán)聲明:本文博主原創(chuàng)文章。博客,未經(jīng)同意不得轉(zhuǎn)載。
總結(jié)
- 上一篇: StringFormat
- 下一篇: 【jQuery】总结:筛选器、控制隐藏、