download zipped/gz file and unzip and use in java

 Example code for downloading a zipped file and unzipping in java

public static void main(String[] args) throws Exception {
String mmdb = "https://someaddress/somefile.gz";
String zipFilename = "somefile.gz";
if (!Files.exists(Path.of(zipFilename))) {
System.out.println(mmdb);
Files.copy(
new URL(mmdb).openStream(),
Paths.get(zipFilename));
try (GZIPInputStream gis = new GZIPInputStream(new FileInputStream(Path.of(zipFilename).toFile()))) {
Files.copy(gis, Path.of(dbFileName));
}
}

SpringApplication.run(Application.class, args);
}

Comments

Popular posts from this blog

Postgresql group by day, week and month examples

Next (2007)