Skip to content

Instantly share code, notes, and snippets.

@LuizGC
Created February 5, 2020 15:27
Show Gist options
  • Save LuizGC/044762e4c8bb9e9e2bb4f56e4a27a5b8 to your computer and use it in GitHub Desktop.
Save LuizGC/044762e4c8bb9e9e2bb4f56e4a27a5b8 to your computer and use it in GitHub Desktop.
Java code to download and unzip files in memory
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