. Net to merge files

Source: Internet
Author: User

The files in the above list are not from allJpgFile, but from

This file.

 

Merging multiple files into one file is very useful in many application fields. Self-implementation of such a program will not only be enjoyable, but will often help us build more efficient programs. Here I will share my case with you.

 

Because the merged file is like a package, this file is called "package file" in the following sections"

 

Main Idea:

To Merge multiple files into a package file, you can also distinguish a file and extract it. We need to know the file name and the location and length of the file in the package file, that is, the so-called address offset.

Because the package file is often large, you should not keep its content in the memory. Instead, you must extract some of the content from the package file.

 

I did this:

 

A manager class that provides some peripheral Methods

 

_ PathListUsed to store the file path to be added to the package file.AddSourceFile ()Add Method

_ PfIs a specific package file, throughLoadPackFile ()Generate an instanceCurrentPackFileProperty return

BuildMethod used to generate a package file

 

 

PackFileClassPackFileManagerIt provides the attributes and construction details of the package file.

 

Okay. Let's take a look.PackFileManager. Build ()Method

Public VoidBuild (StringPath)

{

Using(FileStreamFs =New FileStream(Path,FileMode. Create,FileAccess. Write ))

{

BinaryWriterBw =New BinaryWriter(Fs );

Bw. Write ("PackFile");

Bw. Write (This. _ PathList. Count );

Foreach(StringFIn This. _ PathList)

{

FileInfoFi =New FileInfo(F );

Bw. Write (fi. Length );

Fi =Null;

}

Foreach(StringFIn This. _ PathList)

{

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.