2015-08-14 105 views
-1

我正在讀取位於HDFS中的文件的userId's。我正在通過緩衝讀取器逐行讀取文件並將currentytemdate附加到userId並將其存儲在文件結束後的ArrayList中。我正在將數組列表寫入同一個文件。但我不想添加到arraylist我想讀取行追加currentystemdate並寫入相同的文件是可能的HDFS讀寫操作

回答

0

HDFS主要是關於「一次寫入,多次讀取」。如果您嘗試更新HBase值更好的選項。 在mapreduce作業中,您可以通過TableInputFormat和TableOutputFormat使用。 希望它可以幫助你。

0

我正在讀取位於hdfs中的文件test.txt並將「Kishore」添加到此文件的每一行。根據您的問題更改您的邏輯

import java.io.BufferedWriter; 
import java.io.IOException; 
import java.io.OutputStreamWriter; 

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.FileSystem; 
import org.apache.hadoop.fs.Path; 

public class Append { 
    public static void main(String[] args) throws IOException { 
     Configuration conf = new Configuration(); 
     conf.addResource(new Path(
       "/home/kishore/BigData/hadoop/etc/hadoop/core-site.xml")); 
     String line = "Kishore"; 
     Path path = new Path("hdfs://localhost:9000/test.txt"); 
     FileSystem fs = FileSystem.get(conf); 
     BufferedWriter br = new BufferedWriter(new OutputStreamWriter(
       fs.append(path))); 
     for(int i=0; i< 1000;i++){ 
      br.write(i+"\n"); 

     } 

     br.close(); 

    } 
}