1

I am trying to append some text in HDFS, but it turns out that I have to close the output stream fin_a.close() after every appending. Is there any way which I can append to a file without closing it?

try{
       Path filenamePath = new Path(appId + "_" + "file.txt");
       FSDataOutputStream fin_a = null;
       FSDataOutputStream fin_c = null;
       FileSystem fs = null;
       for(String st : list){
           fs = FileSystem.newInstance(config);
           if(fs.exists(filenamePath)){
             fin_a = fs.append(filenamePath);
             fin_a.writeUTF(st + "\n"));
             fin_a.close();
           } else {
                fin_c = fs.create(filenamePath);
                fin_c.writeUTF(st + "\n"));
                fin_c.close();
             }
       }
       fs.close();
   } catch (IOException e) {
           }

If that's not possible, does anyone have an idea how I can concatenate all the text in the list and write to the file once?

Community
  • 1
  • 1
Self
  • 147
  • 2
  • 16

0 Answers0