Encoding Implementation & amp; gt; file and input/output & amp; gt; Stream

Source: Internet
Author: User

A Stream is a group of continuous data that has the beginning and end, and uses a cursor to indicate the current position.

The data contained in the Stream can be from the memory MemoryStream, file FileStream, or the TCP/IP socket NetWorkStream.

Operations supported by the stream:
 

Read, data is transmitted from Stream to data structure (string or character segment array.

Write, data is transmitted from the data source to the Stream.

Search, query, and modify the position of your Stream.
 

 

Encoding> file and input/output> Stream> create a file Stream

Description: Creates a file path, and specifies the file mode, the access permission is FileAccess, and the shared access permission is FileShare.
 

 

Encoding> file and input/output> Stream> get and set file Stream attributes

Description to determine whether the Stream is readable. It can be set to writable.
 

Create a file stream to obtain and set file stream attributes. Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. IO;

Namespace FileStreamDemo1
{
Class Program
{
Static void Main (string [] args)
{
Const string FilePath = @ "C: MyData. dat ";
Using (FileStream fs = new FileStream (FilePath, FileMode. Create, FileAccess. ReadWrite, FileShare. Read ))
{
Console. WriteLine ("Whether the stream supports readable {0}", fs. CanRead );
Console. WriteLine ("does stream support writable {0}", fs. CanWrite );
Console. WriteLine ("does stream support {0}", fs. CanSeek );
Console. WriteLine ("the current stream Position is {0}", fs. Position );
Console. WriteLine ("Whether the stream is asynchronously opened {0}", fs. IsAsync );
Console. WriteLine ("the stream Length is {0}", fs. Length );
Fs. SetLength (20 );
Console. WriteLine ("new stream Length: {0}", fs. Length );
}
Console. ReadLine ();
}
}
}


 

 

Encoding> file and input/output> Stream> locate and read/write byte arrays to the file Stream

Locate and read/write byte arrays to file streams Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. IO;
Namespace FileStreamReadandwrite
{
Class Program
& Nbs

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.