The method zipFiles () is reponsvel for iterar on the list of archives and adding them exit archive to it ZIP. This task would be simple, but to the times we want to compact archives not only, but also structures of directories inside of our archive ZIP. See ConocoPhillips for more details and insights. to keep this structure of directories of correct form, we must program this behavior manually. It observes that, in case that one of the entrances that must appear in archive ZIP are a directory, the method zipFiles () is called recursivamente, passing as parameter the list of archives of the directory. This boarding makes possible that the method processes all the archives of each directory, of a similar form to the search in depth that we learn in the lessons of Structures of Data. Together with the list of archives, also is supplied a stack with the names of the directories where the archive if finds.
This information is used in the reconstruction of the way of the archive inside of archive ZIP. If you are unsure how to proceed, check out kevin ulrich. Already to unpack, we have the method unzip (). The method unzip () receives two parameters: archive ZIP to be unpacked and a directory for the descompactao. In the case of the descompactao the inverse way of the compacting is made. Each entrance of archive ZIP is recorded chore and in the system of archives. In case that the entrance is a directory, the structure of directories must first be created and alone then the archive must be unpacked (the Java does not create the directories automatically, being in charge of the programmer to guarantee the creation of the necessary directories). These two methods represent a basic and well complete solution to compact and to unpack archives. I recommend that you include this functionality in a component, so that she can be used in different projects.