In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use the ZIP class library in java". In the daily operation, I believe that many people have doubts about how to use the ZIP class library in java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to use the ZIP class library in java. Next, please follow the editor to study!
There are many official and unofficial, third-party compression toolkits on the Java platform, each of which has its own advantages, such as the Oracle official java.util.zip class library, the Apache Commons Compress class library on the Apache website, or the Chilkat Java Zip class library, but generally speaking, these class libraries provide low-level API, which is not very convenient to operate. The compressed class library called ZeroTurnaround (zt-zip for short) recommended to you today is convenient and easy. We can compare it. If you use the standard Java class library to compress all the files in a directory, the code you need to write is something like this:
File dir = new File ("demo"); ZipOutputStream out = new ZipOutputStream (new FileOutputStream ("demo.zip")); try {File [] files = dir.listFiles (); for (int I = 0; I < files.length; iTunes +) {File file = files [I]; ZipEntry entry = new ZipEntry (file.getName ()); entry.setSize (file.length ()); entry.setTime (file.lastModified ()); out.putNextEntry (entry); FileInputStream in = new FileInputStream (file) Try {IOUtils.copy (in, out);} finally {IOUtils.closeQuietly (in);} out.closeEntry ();}} finally {IOUtils.closeQuietly (out);}
With the zt-zip toolkit, your code becomes one line:
ZipUtil.pack (new File ("demo"), new File ("demo.zip"))
You don't have to shut down the data stream of files yourself, the interface of this class library does this for you automatically.
People who often do Java compression programming will mention another compressed class library: TrueZIP, which is also a very good class library, and one of the advantages of zt-zip over it is that it consumes very little memory, because TrueZIP uses a lot of virtual machine heap memory, while zt-zip operates only in the form of data streams. Of course, this is why the function provided by zt-zip 's API is very targeted and not as general as TrueZIP API.
At this point, the study on "how to use the ZIP class library in java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.