Implementing a file splitting Consolidator with C #

Source: Internet
Author: User
Tags constructor file separator file system split visual studio

File separator is mainly to solve the real life of the problem of carrying large files, due to storage media capacity constraints, large files are often not able to copy to the storage media, this can only be separated by the application of the file can be divided into several small files, step-by-step copies of these small files, so as to achieve the purpose of carrying large files. And the role of the Consolidator will be able to merge these small fragmented files, restore the original file. The class library of many processing files provided in the. Net FrameWork SDK enables the simple and flexible implementation of file operations. The main content of this article is to explore the Visual C # in the file programming in a more popular application--file separator and Consolidator. Let's take a look at the class libraries that Visual C # provides for the. Net FrameWork SDK that is used in implementing the split, Consolidator, and how it is used in this article.

A In this paper, the design, commissioning and operation of the environment:

(1). Microsoft Windows 2000 Server Edition.

(2). Visual Studio. NET 2003 Enterprise build,. NET FrameWork SDK version number 4322.

Two Visual C # implements the class library that is used when splitting the merge program and how it is used:

The class libraries that Visual C # uses for programming files are typically in the System.IO namespace in the. Net FrameWork SDK, where the System.IO namespace provides access to the data flow and file levels, which generally provide synchronous, asynchronous two patterns. Visual C # Implementation of the split-merge program is mainly used in the data flow level of the class, mainly: FileStream, BinaryReader and BinaryWriter, these three classes generally provide synchronous, asynchronous mode to access file data flow, this article generally uses the synchronization mode , although there is a lack of performance, but it is very convenient to use, it is not easy to make mistakes.

The FileStream class is a very important class for Visual C # Implementation of file programming, which is embodied in the read and write operations of files in the file system. The FileStream class provides a number of constructors to accommodate a variety of specific operations. This article creates and initializes a FileStream instance by using the string and file-opening method corresponding to the file path. The specific syntax is as follows:

public FileStream (
 string path ,
 FileMode mode
) ;

The following is the specific code that uses this constructor to create and initialize the FileStream instance:

FileStream SplitFileStream = new FileStream ( "C:\\temp.avi" , FileMode.Open ) ;

Table 01 is a common attribute of the FileStream class and its description:

/tr>
description
canread
canseek
canwrite
handle
isasync get instructions Filest Whether the ream is an asynchronous or synchronous open value.
length
Gets the name of the FileStream passed to the constructor.
position
Table 01:filestream class Common properties and their descriptions

The most important thing in the FileStream class is the method in which table 02 is a common method in the FileStream class and its description:

/tr>
method description
beginread
beginwrite
close
endread
endwrite end asynchronous write, in I The/O operation has been blocked until it completes.
flush
lock
read
readbyte read a word from a file Section and raise the read position by one byte.
seek
setlength
unlock
write
writebyte writes a byte to the text The current position of the piece stream.

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.