In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to use the FileStream class of C#", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use the FileStream class of C#" can help you solve your doubts.
FileStream class
The FileStream class in the System.IO namespace helps you read, write and close files. This class is derived from the abstract class Stream.
You need to create a FileStream object to create a new file, or to open an existing file. The syntax for creating a FileStream object is as follows:
FileStream = new FileStream (,)
For example, create a FileStream object F to read a file named sample.txt:
FileStream F = new FileStream ("sample.txt", FileMode.Open, FileAccess.Read, FileShare.Read); parameter description FileMode
The FileMode enumeration defines various methods for opening files. The members of the FileMode enumeration are:
Append: open an existing file and place the cursor at the end of the file. If the file does not exist, create the file.
Create: create a new file. If the file already exists, delete the old file, and then create a new one.
CreateNew: specifies that the operating system should create a new file. If the file already exists, an exception is thrown.
Open: open an existing file. If the file does not exist, an exception is thrown.
OpenOrCreate: specifies that the operating system should open an existing file. If the file does not exist, a new file is created with the specified name to open.
Truncate: open an existing file, once opened, it will be truncated to zero byte size. We can then write new data to the file, but keep the initial creation date of the file. If the file does not exist, an exception is thrown.
FileAccess
The members of the FileAccess enumeration are Read, ReadWrite, and Write.
FileShare
The members of the FileShare enumeration are:
Inheritable: allows file handles to be inherited by child processes. Win32 does not directly support this feature.
None: declined to share the current file. Any request to open the file (a request from this process or another) will fail before the file is closed.
Read: allows you to open the file and read it later. If this flag is not specified, any requests to open the file for reading (requests made by this process or another process) will fail before the file is closed. However, even if this flag is specified, additional permissions may be required to access the file.
ReadWrite: allows the file to be opened later for reading or writing. If this flag is not specified, any request to open the file for reading or writing (issued by this process or another process) will fail before the file is closed. However, even if this flag is specified, additional permissions may be required to access the file.
Write: allows you to open the file to write later. If this flag is not specified, any request to open the file for writing (requests made by this process or another forward process) will fail before the file is closed. However, even if this flag is specified, additional permissions may be required to access the file.
Delete: allows files to be deleted later.
After reading this, the article "how to use the FileStream class of C#" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.