Java implementation of Zip compressed file decompression

Source: Internet
Author: User
Tags md5 encryption ftp transfer

Requirements Description:

A while ago wrote a blog "Java implementation of the text file MD5 encryption and FTP transfer to the remote host directory ," to achieve a part of the business requirements. However, some businesses may not only send a file, sometimes customers need to pass multiple files, the original system does not support, so now need to build on this basis a new feature, it is required to implement the business scenario, the transfer of multiple files to the remote host specified directory.

Business Grooming:

For this requirement, I have two ideas, idea one is to set up an array of information for the user to select multiple files, Java side for the object of the file by clicking the File Upload button when selecting the file, but this method, I try to set the <s:file ></s of struts: file> tag attribute multiple= "Multiple", also did not realize want to achieve the effect, look at the whole network of multiple blog No fruit had to abandon the idea of one.

The second idea is that the user uploads the text file that needs to be uploaded, into a zip package, after Java obtains the file, extracts it, then iterates through the files in that directory, encrypts each file MD5, generates a MD5 file with the same name, and obtains the IP, account, password, and the uploaded directory information.

The approximate flowchart is as follows:

Program implementation:

First, the front interface

Because it is a new business scenario, the foreground interface needs to be modified, providing a drop-down option for the business people to choose from.

Need to restrict the types of files uploaded by the business people, written in the JS function

Implementation of the foreground interface:

Second, the operation of the file object

After the user uploads the file, the system obtains the file object through Struts2 and copies it to the datapath randomly generated subdirectory.

Here we begin to judge the file type, and if it is a file type with a suffix of zip, call ziputil. Unzip (NewFile, DataPath) method to extract the file object, after extracting, traverse the directory file, if the suffix is ". 000", then MD5 encryption, generate the same name MD5 file, this action is by calling FILEMD5.GETMD5 (fortmp) method to complete the process. Finally, after the operation, in order to avoid the zip file upload, so here through Newfile.delete () to delete the file.

The decompression method is ziputil. Unzip, here used to Ant.jar, need to import, or add Maven pom dependency, here only write a zip decompression method, and did not write to other formats such as RAR decompression.

MD5 encryption algorithm and generate MD5 file, you can refer to the previous blog,Java implementation of the text file MD5 encryption and FTP transfer to the remote host directory , no longer described here, or refer to the online blog.

Third, obtain the host's IP, account, password, directory information and implementation of the upload

These actions are mentioned in the previous blog post, just send a picture here

The operationtype of the foreground interface corresponds to the Audit_flag in the Database configuration table, and the Java call ibaits the SQL of the image below to get the relevant information.

Implementation of the current folder file upload in the previous blog also mentioned, here I just paste a picture

Finally, the feedback results.

Summarize:

This blog in the previous blog based on the implementation of the zip upload file decompression, the extracted files for MD5 encryption to generate the same name MD5 file, and then implement FTP upload to the remote host. Where the business process is as shown

If you have a need you can go to the https://github.com/rootzhongfengshan/the-repository-of-zhongfengshan.git in the Java_ Get the Zip source code under project directory.

Java implementation of Zip compressed file decompression

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.