-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZipFileManipulator with target file extract ready
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.io.BufferedInputStream; | ||
import java.io.BufferedOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Enumeration; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
public class ZipFileManipulator { | ||
|
||
private String fileName; // file which will be extracted from | ||
private String extractionPath; // temporary path where the file will be extracted to | ||
|
||
public ZipFileManipulator(String fileName, String extractionPath) { | ||
this.fileName = fileName; | ||
this.extractionPath = extractionPath; | ||
} | ||
|
||
public void extractFile(String targetFile) throws Exception { | ||
File outputLocation = new File(extractionPath, targetFile); | ||
|
||
// path to the file the file will be extracted from | ||
Path zipFile = Paths.get(fileName); | ||
|
||
// load zip file as filesystem | ||
FileSystem fileSystem = FileSystems.newFileSystem(zipFile, null); | ||
|
||
Path source = fileSystem.getPath("ppt/" + targetFile); // location of targetFile inside the zip file | ||
|
||
Files.copy(source, outputLocation.toPath()); | ||
} | ||
|
||
} |