Created
June 30, 2020 14:37
-
-
Save dashdanw/d63658d4623c619b4690a48ada861e56 to your computer and use it in GitHub Desktop.
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
package com.dash; | |
import java.io.*; | |
import java.io.FileOutputStream; | |
import java.nio.file.DirectoryStream; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.nio.file.Path; | |
import java.io.IOException; | |
import java.util.zip.GZIPOutputStream; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
Path dir = Paths.get("C:\\Users\\dashd\\IdeaProjects\\"); | |
File zipFile = new File("C:\\Users\\dashd\\out.gz"); | |
FileOutputStream fos = new FileOutputStream(zipFile); | |
GZIPOutputStream gos = new GZIPOutputStream(fos); | |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { | |
for (Path entry : stream) { | |
if (entry.toFile().isFile()) { | |
FileInputStream fis = new FileInputStream(entry.toFile()); | |
gos.write(fis.readAllBytes()); | |
} | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
gos.close(); | |
fos.close(); | |
byte[] fileContent = Files.readAllBytes(zipFile.toPath()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment