Created
February 5, 2020 15:27
-
-
Save LuizGC/044762e4c8bb9e9e2bb4f56e4a27a5b8 to your computer and use it in GitHub Desktop.
Java code to download and unzip files in memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URL; | |
import java.net.URLConnection; | |
import java.nio.charset.StandardCharsets; | |
import java.util.zip.ZipInputStream; | |
public class Main { | |
public static void main(String... args) throws Exception { | |
URL url = new URL(args[0]); | |
URLConnection con = url.openConnection(); | |
ZipInputStream zipStream = new ZipInputStream(con.getInputStream()); | |
while (zipStream.getNextEntry() != null) { | |
byte[] buffer = new byte[1]; | |
while (zipStream.read(buffer) > 0) { | |
String character = new String(buffer, StandardCharsets.UTF_8); | |
if (character.equals("\\r?\\n")){ | |
System.out.println(""); | |
} else { | |
System.out.print(character); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment