Advertisement
kevin3stone

Unzip a file to a specific folder

Dec 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1.     private void transferDashboardTool(String destination) throws IOException {
  2.  
  3.         final String resourcePath = "classpath:dashboard/dashboard.zip";
  4.         File file = new File(Paths.get(System.getProperty("java.io.tmpdir"), "tmp.zip").toString());
  5.         FileUtils.copyInputStreamToFile(resourceLoader.getResource(resourcePath).getInputStream(), file);
  6.         ZipFile zipFile = new ZipFile(file);
  7.         zipFile.extractAll(destination);
  8.     }
  9.  
  10. // points
  11. // 1. make sure you are using resource.getInputStream() not resource.getFile() when loading from inside a jar file
  12. // 2. how to get a temporary folder
  13. // 3. how to convert InputStream to File with Apache common.io
  14. // 4. how to unzip file using zip4j (http://www.lingala.net/zip4j.html) library
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement