public static String getZipStringContentsRecursive ( final String file ) throws IOException { // return local file directly int pos = file . indexOf ( ' ' ) ; if ( pos == - 1 ) { if ( ! new File ( file ) . exists ( ) ) { throw new IOException ( "File " + file + " does not exist" ) ; } try { try ( InputStream str = new FileInputStream ( file ) ) { if ( str . available ( ) > 0 ) { return IOUtils . toString ( str , "UTF-8" ) ; } return "" ; } } catch ( IOException e ) { // filter out locked errors if ( e . getMessage ( ) . contains ( "because another process has locked" ) ) { logger . warning ( "Could not read file: " + file + " because it is locked." ) ; return "" ; } throw e ; } } String zip = file . substring ( 0 , pos ) ; String subfile = file . substring ( pos + 1 ) ; if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Trying to read zipfile: " + zip + " subfile: " + subfile ) ; } // open original zip if ( ! new File ( zip ) . exists ( ) || ! new File ( zip ) . isFile ( ) || ! new File ( zip ) . canRead ( ) || new File ( zip ) . length ( ) == 0 ) { throw new IOException ( "ZIP file: " + zip + " does not exist or is empty or not a readable file." ) ; } try ( ZipFile zipfile = new ZipFile ( zip ) ) { // is the target file in yet another ZIP file? pos = subfile . indexOf ( ' ' ) ; if ( pos != - 1 ) { // find out first ZIP file and remainder String remainder = subfile . substring ( pos + 1 ) ; File subzipfile = File . createTempFile ( "SearchZip" , ".zip" ) ; try { readToTemporaryFile ( pos , zip , subfile , zipfile , subzipfile ) ; // start another recursion with the temporary file and the remainder return getZipStringContentsRecursive ( subzipfile . getAbsolutePath ( ) + ZIP_DELIMITER + remainder ) ; } finally { if ( ! subzipfile . delete ( ) ) { logger . warning ( "Could not delete file " + subzipfile ) ; } } } ZipEntry entry = zipfile . getEntry ( subfile ) ; try ( InputStream str = zipfile . getInputStream ( entry ) ) { if ( str . available ( ) > 0 ) { return IOUtils . toString ( str , "UTF-8" ) ; } return "" ; } } }
Get the text - contents of the noted file . An exclamation mark ! denotes a zip - entry . ZIP files can be nested inside one another .