0

I have a zip file in hdfs and i need to add a file to the zip and save in the same HDFS location. Any examples would be appreciated.

I have the following code.

  val filePattern =  s"${hdfsFolderPath}/${filePath}.txt"
  val zipFilePath = hdfsWrapper.getFileNameFromPattern(s"${targetFilePath}/*.zip")

  if (hdfsWrapper.filter(filePattern).size() > 0)
    {
      Try
      {
        val zipEntry = new ZipEntry(filePattern)
         val zos: ZipOutputStream = new ZipOutputStream(new FileOutputStream(zipFilePath))
        zos.putNextEntry(zipEntry)            
        zos.closeEntry()
        zos.close()
      }
    }

Would like to know if above code is right?

jwvh
  • 50,871
  • 7
  • 38
  • 64
user3897533
  • 417
  • 1
  • 8
  • 24

1 Answers1

0

I believe that your code would result in the zip file being replaced with a new one containing just the new file. See Appending files to a zip file with Java for an example of adding a file to a zip archive.

I'm not extremely familiar with HDFS, but I suspect that you can't write to that directly either, you probably have to create the new zip file and then replace it in HDFS

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67