我正在从位于HDFS中的文件中读取userId。我通过缓冲读取器逐行读取文件并将currentytemdate附加到userId并在文件结束后将其存储在arraylist中我将数组列表写入同一文件。但我不想添加到arraylist我想读取行追加currentystemdate并写入相同的文件是否可能
答案 0 :(得分:0)
答案 1 :(得分: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();
}
}