至HDFS附加内容
在最近的項目開發中遇到的問題:
需要產生良好hdfs文件的其他內容。但使用在線版1.0.3。見發現官方文件,于1.0.4支持的文件的版本號之后append
一下是向hdfs中追加信息的操作方法
假設你僅僅在某一個driver中追加內容信息。不必要對于整個HDFS都開啟內容追加:
在某個方法中。追加文件信息:
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中的文件內容
假設須要開啟對于整個HDFS的文件追加內容權限須要在
hdfs-site.xml中添加下面配置
<property>
? ? <name>dfs.support.append</name>
? ? <value>true</value>
</property>
需要產生良好hdfs文件的其他內容。但使用在線版1.0.3。見發現官方文件,于1.0.4支持的文件的版本號之后append
一下是向hdfs中追加信息的操作方法
假設你僅僅在某一個driver中追加內容信息。不必要對于整個HDFS都開啟內容追加:
在某個方法中。追加文件信息:
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中的文件內容
假設須要開啟對于整個HDFS的文件追加內容權限須要在
hdfs-site.xml中添加下面配置
<property>
? ? <name>dfs.support.append</name>
? ? <value>true</value>
</property>
版權聲明:本文博主原創文章。博客,未經同意不得轉載。
總結
- 上一篇: StringFormat
- 下一篇: 【jQuery】总结:筛选器、控制隐藏、