Extracting all files from a ZIP archive

Report a typo

Organize these code fragments in an order that successfully completes the task according to the given parameters.

Objective: Your task is to write Kotlin code to extract files from a ZIP archive.

Task Description:

  1. Import the necessary modules for handling files and ZIP archives.

  2. Open a ZIP file named "example.zip".

  3. Apply a functional approach for managing resources, automatically closing them after use.

  4. Go through all the entries in the ZIP archive.

  5. Create an input stream for each entry.

  6. Generate an output stream to write data to a file named after the current archive entry.

  7. Transfer the data from the input stream to the output stream.

Reorder lines using drag or arrows. Adjust indentation with left buttons
                }
              
                import java.util.zip.ZipFile // first line
              
                import java.io.*
              
                zip.entries().asSequence().forEach { entry ->
              
                zip.getInputStream(entry).use { input ->
              
                }
              
                BufferedOutputStream(FileOutputStream(entry.name)).use { output ->
              
                }
              
                ZipFile("example.zip").use { zip ->
              
                }
              
                input.copyTo(output)
              

Create a free account to access the full topic