개요
클라이언트에서 zip 파일을 업로드했을 때 zip 파일 내 tar.gz 파일만 추출해서 NAS에 저장하도록 로직을 바꿔야 했습니다.
찾아본 결과 추출할 파일명만 안다면 생각보다 간단하게 코드를 작성할 수 있었습니다.
코드
비고
같은 Java 8버전이더라도 JDK-8223197 버전 이전 버전을 사용할 경우 FileSystem.newFileSystem(zipFilePath, null) 코드에서 ambiguous가 뜰 것입니다.
https://bugs.openjdk.java.net/browse/JDK-8223197
[JDK-8223197] Release Note: Added FileSystems.newFileSystem(Path, Map<String, ?>) Method - Java Bug System
Three new methods have been added to `java.nio.file.FileSystems` to make it easier to use file system providers that treat the contents of a file as a file system. - `newFileSystem(Path)` - `newFileSystem(Path, Map<String, ?>)` - `newFileSystem(Path, Map<S
bugs.openjdk.java.net
이전 버전일 경우 FileSystem.newFileSystem(zipFilePath, ClassLoader.getSystemClassLoader());로 하면 될 것입니다.
참고
https://stackoverflow.com/questions/32179094/how-to-extract-specific-file-in-a-zip-file-in-java
How to extract specific file in a zip file in java
I need to provide a view of zip file to customer in system, and allow customers download choosed files. parse the zip file and show on the web page. and remember every zipentry location(for example
stackoverflow.com
'[DEV] 기록' 카테고리의 다른 글
[Maven + Tomcat] 메이븐 빌드 후 톰캣에 war 배포하는 방법 (0) | 2022.06.02 |
---|---|
[linux] linux 명령어 정리 (2) | 2022.06.01 |
[Java] UTF-8로 파일 작성하는 코드 (0) | 2022.05.29 |
[ssh] ssh 접속하는 방법 (0) | 2022.05.17 |
[Nginx] Nginx Reverse Proxy 정리 (0) | 2022.05.17 |