Extract specific file from ZIP in Kotlin

Report a typo

You need to create a function that accepts a ZIP file path and a certain file name as arguments. Your function should take out this particular file from the ZIP file and save it in a specific directory.

Reorder lines using drag or arrows. Adjust indentation with left buttons
                zip.getInputStream(entry).use { input ->
              
                Files.createDirectories(Paths.get(outputDir))
              
                FileOutputStream("$outputDir/$fileName").use { output ->
              
                try {
              
                }
              
                fun extractSpecificFile(zipFilePath: String, fileName: String, outputDir: String) {
              
                ZipFile(zipFilePath).use { zip ->
              
                }
              
                }
              
                input.copyTo(output)
              
                }
              
                extractSpecificFile("path/to/zipfile.zip", "specificfile.txt", "output/directory")
              
                }
              
                val entry = zip.getEntry(fileName) ?: throw FileNotFoundException("File $fileName not found in zip")
              
                } catch (e: IOException) {
              
                e.printStackTrace()
              
                fun main() {
              
                }
              

Create a free account to access the full topic