C# new file




















Creates or overwrites a file in the specified path, specifying a buffer size. Create String, Int32, FileOptions. CreateSymbolicLink String, String.

CreateText String. Decrypt String. Delete String. Encrypt String. Encrypts a file so that only the account used to encrypt the file can decrypt it. Exists String. GetAccessControl String. GetAttributes String. GetCreationTime String. Returns the creation date and time of the specified file or directory. GetCreationTimeUtc String. GetLastAccessTime String. Returns the date and time the specified file or directory was last accessed.

GetLastWriteTime String. Returns the date and time the specified file or directory was last written to. Move String, String. Moves a specified file to a new location, providing the option to specify a new file name.

Move String, String, Boolean. Open String, FileMode. Open String, FileStreamOptions. OpenRead String. OpenText String. OpenWrite String. ReadAllBytes String. Opens a binary file, reads the contents of the file into a byte array, and then closes the file. ReadAllLines String. Opens a text file, reads all lines of the file, and then closes the file.

ReadAllLines String, Encoding. Opens a file, reads all lines of the file with the specified encoding, and then closes the file. Asynchronously opens a text file, reads all lines of the file, and then closes the file. ReadAllText String. Opens a text file, reads all the text in the file, and then closes the file.

ReadAllText String, Encoding. Opens a file, reads all text in the file with the specified encoding, and then closes the file. Asynchronously opens a text file, reads all the text in the file, and then closes the file. ReadLines String. ReadLines String, Encoding. Replace String, String, String. Replace String, String, String, Boolean. ResolveLinkTarget String, Boolean. SetAttributes String, FileAttributes. Sets the date and time, in coordinated universal time UTC , that the file was created.

WriteAllBytes String, Byte[]. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services.

Privacy policy. Thank you. Microsoft makes no warranties, express or implied, with respect to the information provided here. Provides a Stream for a file, supporting both synchronous and asynchronous read and write operations.

The following example demonstrates some of the FileStream constructors. The following example shows how to write to a file asynchronously. The file path needs to be changed to a file that exists on the computer. Use the FileStream class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output.

Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a Windows 8.

FileStream buffers input and output for better performance. This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of it indirectly, use a language construct such as using in C or Using in Visual Basic. The IsAsync property detects whether the file handle was opened asynchronously. You specify this value when you create an instance of the FileStream class using a constructor that has an isAsync , useAsync , or options parameter.

The Seek method supports random access to files. This is done with byte offset reference point parameters. The byte offset is relative to the seek reference point, which can be the beginning, the current position, or the end of the underlying file, as represented by the three members of the SeekOrigin enumeration. Disk files always support random access. At the time of construction, the CanSeek property value is set to true or false depending on the underlying file type.

Otherwise, the CanSeek property value is false. If a process terminates with part of a file locked or closes a file that has outstanding locks, the behavior is undefined.

For directory operations and other file operations, see the File , Directory , and Path classes. The File class is a utility class that has static methods primarily for the creation of FileStream objects based on file paths. The MemoryStream class creates a stream from a byte array and is similar to the FileStream class.

When a FileStream object does not have an exclusive hold on its handle, another thread could access the file handle concurrently and change the position of the operating system's file pointer that is associated with the file handle.

In this case, the cached position in the FileStream object and the cached data in the buffer could be compromised. The FileStream object routinely performs checks on methods that access the cached buffer to ensure that the operating system's handle position is the same as the cached position used by the FileStream object. If an unexpected change in the handle position is detected in a call to the Read method, the. NET Framework discards the contents of the buffer and reads the stream from the file again.

This can affect performance, depending on the size of the file and any other processes that could affect the position of the file stream. If an unexpected change in the handle position is detected in a call to the Write method, the contents of the buffer are discarded and an IOException exception is thrown. A FileStream object will not have an exclusive hold on its handle when either the SafeFileHandle property is accessed to expose the handle or the FileStream object is given the SafeFileHandle property in its constructor.

Initializes a new instance of the FileStream class with the specified path and creation mode. Initializes a new instance of the FileStream class with the specified path, creation mode, access rights and sharing permission, the buffer size, and additional file options. Initializes a new instance of the FileStream class with the specified path, creation mode, access rights and sharing permission, the buffer size, additional file options, access control and audit security.

Gets the operating system file handle for the file that the current FileStream object encapsulates. Gets a value that indicates whether the FileStream was opened asynchronously or synchronously. Gets the absolute path of the file opened in the FileStream.

Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. Gets a SafeFileHandle object that represents the operating system file handle for the file that the current FileStream object encapsulates.

Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out. Begins an asynchronous read operation. Begins an asynchronous write operation. Your message has been sent to W3Schools. W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use , cookie and privacy policy.

Copyright by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.



0コメント

  • 1000 / 1000