Asp.net Summary of files and streams

Source: Internet
Author: User

OperationCompositionComponent class
File methods are static and suitable for performing only one operation. All methods are performing a security check.
The fileinfo class is suitable for providing an object for a file that performs multiple operations, but only performs one security check.

Operation Directory class
Directory
Directoryinfo
Same as file class

Path class

Stream is the abstract base class of all streams. Its sub-classes include stream in memory of memorystream, stream of filestream files, stream of networkstream network devices, and other stream of bufferedstream.
Main Methods
Read (), read the stream into the byte array
Write (), write the byte array into the stream
Flush () to write the buffered stream into the target
Close (), close the stream to release resources

Binary files
Type of the data to be obtained

Text Files
Streamreader and streamwriter operate the stream as characters

Upload files
Request. Files [0]. inputstream
After obtaining the uploaded byte stream, if the byte stream is closed, it cannot be used directly later. This is because the resource has been released.

// Stream, byte array and String Conversion stream-byte array-string
Stream stream = new filestream (@ "1.html", filemode. Open, fileaccess. Read, fileshare. Read );
Byte [] bytes = new byte [stream. Length];
Stream. Read (bytes, 0, bytes. Length-1 );
String STR = encoding. utf8.getstring (bytes );

Byte [] bytes2 = encoding. utf8.getbytes (STR );
Stream streamm = new memorystream (bytes2 );

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.