Source Code : Read files within a zip file

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Read files within a zip file

         

import java.io.File;
import java.io.FileInputStream;
import java.io.RandomAccessFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
  public static void main(String[] args) throws Exception{
    ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream("filename"));
    ZipEntry zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) {
      String entryName = zipentry.getName();
      File newFile = new File(entryName);
      String directory = newFile.getParent();
      if (directory == null) {
        if (newFile.isDirectory())
          break;
      }
      RandomAccessFile  rf = new RandomAccessFile(entryName, "r");
      String line;
      if ((line = rf.readLine()) != null) {
        System.out.println(line);
      }
      rf.close();
      zipinputstream.closeEntry();
      zipentry = zipinputstream.getNextEntry();
    }
    zipinputstream.close();
  }
}

   
    
    
    
    
    
    
    
    
  

Thank with us