textfilestream_FileStream

FileStream 类

定义

程序集:mscorlib.dll, System.IO.FileSystem.dll

程序集:System.Runtime.dll

程序集:System.IO.FileSystem.dll

程序集:mscorlib.dll

程序集:netstandard.dll

为文件提供 Stream,既支持同步读写操作,也支持异步读写操作。Provides a Stream for a file, supporting both synchronous and asynchronous read and write operations.

本文内容

public ref class FileStream : System::IO::Stream

public class FileStream : System.IO.Stream

[System.Runtime.InteropServices.ComVisible(true)]

public class FileStream : System.IO.Stream

type FileStream = class

inherit Stream

[]

type FileStream = class

inherit Stream

Public Class FileStream

Inherits Stream

继承

示例

下面的示例演示一些 FileStream 构造函数。The following example demonstrates some of the FileStream constructors.

using namespace System;

using namespace System::IO;

using namespace System::Text;

void AddText( FileStream^ fs, String^ value )

{

array^info = (gcnew UTF8Encoding( true ))->GetBytes( value );

fs->Write( info, 0, info->Length );

}

int main()

{

String^ path = "c:\\temp\\MyTest.txt";

// Delete the file if it exists.

if ( File::Exists( path ) )

{

File::Delete( path );

}

//Create the file.

{

FileStream^ fs = File::Create( path );

try

{

AddText( fs, "This is some text" );

AddText( fs, "This is some more text," );

AddText( fs, "\r\nand this is on a new line" );

AddText( fs, "\r\n\r\nThe following is a subset of characters:\r\n" );

for ( int i = 1; i < 120; i++ )

{

AddText( fs, Convert::ToChar( i ).ToString() );

//Split the output at every 10th character.

if ( Math::IEEERemainder( Convert::ToDouble( i ), 10 ) == 0 )

{

AddText( fs, "\r\n" );

}

}

}

finally

{

if ( fs )

delete (IDisposable^)fs;

}

}

//Open the stream and read it back.

{

FileStream^ fs = File::OpenRead( path );

try

{

array^b = gcnew array(1024);

UTF8Encoding^ temp = gcnew UTF8Encoding( true );

while ( fs->Read( b, 0, b->Length ) > 0 )

{

Console::WriteLine( temp->GetString( b ) );

}

}

finally

{

if ( fs )

delete (IDisposable^)fs;

}

}

}using System;

using System.IO;

using System.Text;

class Test

{

public static void Main()

{

string path = @"c:\temp\MyTest.txt";

// Delete the file if it exists.

if (File.Exists(path))

{

File.Delete(path);

}

//Create the file.

using (FileStream fs = File.Create(path))

{

AddText(fs, "This is some text");

AddText(fs, "This is some more text,");

AddText(fs, "\r\nand this is on a new line");

AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n");

for (int i=1;i < 120;i++)

{

AddText(fs, Convert.ToChar(i).ToString());

}

}

//Open the stream and read it back.

using (FileStream fs = File.OpenRead(path))

{

byte[] b = new byte[1024];

UTF8Encoding temp = new UTF8Encoding(true);

while (fs.Read(b,0,b.Length) > 0)

{

Console.WriteLine(temp.GetString(b));

}

}

}

private static void AddText(FileStream fs, string value)

{

byte[] info = new UTF8Encoding(true).GetBytes(value);

fs.Write(info, 0, info.Length);

}

}Imports System.IO

Imports System.Text

Public Class Test

Public Shared Sub Main()

Dim path As String = "c:\temp\MyTest.txt"

' Delete the file if it exists.

If File.Exists(path) Then

File.Delete(path)

End If

'Create the file.

Dim fs As FileStream = File.Create(path)

AddText(fs, "This is some text")

AddText(fs, "This is some more text,")

AddText(fs, Environment.NewLine & "and this is on a new line")

AddText(fs, Environment.NewLine & Environment.NewLine)

AddText(fs, "The following is a subset of characters:" & Environment.NewLine)

Dim i As Integer

For i = 1 To 120

AddText(fs, Convert.ToChar(i).ToString())

Next

fs.Close()

'Open the stream and read it back.

fs = File.OpenRead(path)

Dim b(1023) As Byte

Dim temp As UTF8Encoding = New UTF8Encoding(True)

Do While fs.Read(b, 0, b.Length) > 0

Console.WriteLine(temp.GetString(b))

Loop

fs.Close()

End Sub

Private Shared Sub AddText(ByVal fs As FileStream, ByVal value As String)

Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)

fs.Write(info, 0, info.Length)

End Sub

End Class

下面的示例演示如何以异步方式写入文件。The following example shows how to write to a file asynchronously. 此代码在具有名为 U s 的 TextBlock 的 WPF 应用中运行,并将按钮挂钩到名为 Button_Click 的 Click 事件处理程序。This code runs in a WPF app that has a TextBlock named UserInput and a button hooked up to a Click event handler that is named Button_Click. 文件路径需要更改为计算机上存在的文件。The file path needs to be changed to a file that exists on the computer.

using System;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.IO;

namespace WpfApplication1

{

public partial class MainWindow : Window

{

public MainWindow()

{

InitializeComponent();

}

private async void Button_Click(object sender, RoutedEventArgs e)

{

UnicodeEncoding uniencoding = new UnicodeEncoding();

string filename = @"c:\Users\exampleuser\Documents\userinputlog.txt";

byte[] result = uniencoding.GetBytes(UserInput.Text);

using (FileStream SourceStream = File.Open(filename, FileMode.OpenOrCreate))

{

SourceStream.Seek(0, SeekOrigin.End);

await SourceStream.WriteAsync(result, 0, result.Length);

}

}

}

}Imports System.IO

Imports System.Text

Class MainWindow

Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)

Dim uniencoding As UnicodeEncoding = New UnicodeEncoding()

Dim filename As String = "c:\Users\exampleuser\Documents\userinputlog.txt"

Dim result As Byte() = uniencoding.GetBytes(UserInput.Text)

Using SourceStream As FileStream = File.Open(filename, FileMode.OpenOrCreate)

SourceStream.Seek(0, SeekOrigin.End)

Await SourceStream.WriteAsync(result, 0, result.Length)

End Using

End Sub

End Class

注解

使用 FileStream 类来读取、写入、打开和关闭文件系统上的文件,以及操作与文件相关的其他操作系统句柄,包括管道、标准输入和标准输出。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. You can use the Read, Write, CopyTo, and Flush methods to perform synchronous operations, or the ReadAsync, WriteAsync, CopyToAsync, and FlushAsync methods to perform asynchronous operations. 使用异步方法来执行占用大量资源的文件操作,而不会阻止主线程。Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. 在 Windows 8.x 应用商店Windows 8.x Store 应用或 桌面desktop 应用中一个耗时的流操作可能阻塞 UI 线程并让您的应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。This performance consideration is particularly important in a Windows 8.x 应用商店Windows 8.x Store app or 桌面desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. FileStream 缓冲输入和输出以提高性能。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. 若要直接释放类型,请在 try/catch 块中调用其 Dispose 方法。To dispose of the type directly, call its Dispose method in a try/catch block. 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

IsAsync属性检测文件句柄是否已异步打开。The IsAsync property detects whether the file handle was opened asynchronously. FileStream使用具有 isAsync 、 useAsync 或参数的构造函数创建类的实例时,可以指定此值 options 。You specify this value when you create an instance of the FileStream class using a constructor that has an isAsync, useAsync, or options parameter. 当属性为时 true ,流将使用重叠的 i/o 以异步方式执行文件操作。When the property is true, the stream utilizes overlapped I/O to perform file operations asynchronously. However, the IsAsync property does not have to be true to call the ReadAsync, WriteAsync, or CopyToAsync method. 当 IsAsync 属性为, false 并且您调用异步读写操作时,UI 线程仍不会被阻止,但实际的 i/o 操作将以同步方式执行。When the IsAsync property is false and you call the asynchronous read and write operations, the UI thread is still not blocked, but the actual I/O operation is performed synchronously.

Seek方法支持对文件进行随机访问。The Seek method supports random access to files. Seek 允许读/写位置移动到文件中的任何位置。Seek allows the read/write position to be moved to any position within the file. 这是通过字节偏移量引用点参数实现的。This is done with byte offset reference point parameters. 字节偏移量是相对于查找引用点的,它可以是基础文件的开头、当前位置或末尾,由枚举的三个成员表示 SeekOrigin 。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. 在构造时, CanSeek 属性值设置为 true 或, false 具体取决于基础文件类型。At the time of construction, the CanSeek property value is set to true or false depending on the underlying file type. 如果基础文件类型是 FILE_TYPE_DISK (如 winbase.h 中所定义),则 CanSeek 属性值为 true 。If the underlying file type is FILE_TYPE_DISK, as defined in winbase.h, the CanSeek property value is true. 否则, CanSeek 属性值为 false 。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.

有关目录操作和其他文件操作,请参阅 File 、 Directory 和 Path 类。For directory operations and other file operations, see the File, Directory, and Path classes. File类是一个实用工具类,该类具有用于 FileStream 基于文件路径创建对象的静态方法。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.

有关常见文件和目录操作的列表,请参阅 常见 I/o 任务。For a list of common file and directory operations, see Common I/O Tasks.

检测流位置更改Detection of Stream Position Changes

如果 FileStream 对象在其句柄上没有独占保留,另一个线程可以同时访问文件句柄,并更改与文件句柄关联的操作系统文件指针的位置。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. 在这种情况下,对象中缓存的位置 FileStream 和缓冲区中的缓存数据可能会泄露。In this case, the cached position in the FileStream object and the cached data in the buffer could be compromised. FileStream对象定期对访问缓存的缓冲区的方法执行检查,以确保操作系统的句柄位置与对象使用的缓存位置相同 FileStream 。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.

如果在调用方法时检测到句柄位置发生意外更改 Read ,.NET Framework 会丢弃缓冲区的内容,并再次从文件读取流。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.

如果在调用方法时检测到句柄位置发生意外更改,则会 Write 丢弃缓冲区的内容并 IOException 引发异常。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.

构造函数

已过时。

已过时。

已过时。

使用指定的读/写权限为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission.

已过时。

已过时。

已过时。

使用指定的读/写权限和 FileStream 实例所属权为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission and FileStream instance ownership.

已过时。

已过时。

已过时。

使用指定的读/写权限、FileStream 实例所属权和缓冲区大小为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission, FileStream instance ownership, and buffer size.

已过时。

已过时。

已过时。

使用指定的读/写权限、FileStream 实例所属权、缓冲区大小和同步或异步状态为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission, FileStream instance ownership, buffer size, and synchronous or asynchronous state.

使用指定的读/写权限为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission.

使用指定的读/写权限和缓冲区大小为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission, and buffer size.

使用指定的读/写权限、缓冲区大小和同步或异步状态为指定的文件句柄初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission, buffer size, and synchronous or asynchronous state.

使用指定的路径和创建模式初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class with the specified path and creation mode.

使用指定的路径、创建模式和读/写权限初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class with the specified path, creation mode, and read/write permission.

使用指定的路径、创建模式、读/写权限和共享权限创建 FileStream 类的新实例。Initializes a new instance of the FileStream class with the specified path, creation mode, read/write permission, and sharing permission.

用指定的路径、创建模式、读/写及共享权限和缓冲区大小初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, and buffer size.

使用指定的路径、创建模式、读/写和共享权限、缓冲区大小和同步或异步状态初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, buffer size, and synchronous or asynchronous state.

使用指定的路径、创建模式、读/写和共享权限、其他 FileStreams 可以具有的对此文件的访问权限、缓冲区大小和附加文件选项初始化 FileStream 类的新实例。Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, the access other FileStreams can have to the same file, the buffer size, and additional file options.

使用指定的路径、创建模式、访问权限和共享权限、缓冲区大小和附加文件选项初始化 FileStream 类的新实例。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.

使用指定的路径、创建模式、访问权限和共享权限、缓冲区大小、附加文件选项、访问控制和审核安全初始化 FileStream 类的新实例。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 a value that indicates whether the current stream supports reading.

获取一个值,该值指示当前流是否支持查找。Gets a value that indicates whether the current stream supports seeking.

获取一个值,该值确定当前流是否可以超时。Gets a value that determines whether the current stream can time out.

(继承自 Stream)

获取一个值,该值指示当前流是否支持写入。Gets a value that indicates whether the current stream supports writing.

已过时。

已过时。

已过时。

获取当前 FileStream 对象所封装文件的操作系统文件句柄。Gets the operating system file handle for the file that the current FileStream object encapsulates.

获取一个值,它指示 FileStream 是异步打开还是同步打开的。Gets a value that indicates whether the FileStream was opened asynchronously or synchronously.

获取流的长度(以字节为单位)。Gets the length in bytes of the stream.

获取 FileStream 中已打开的文件的绝对路径。Gets the absolute path of the file opened in the FileStream.

获取或设置此流的当前位置。Gets or sets the current position of this stream.

获取或设置一个值(以毫秒为单位),该值确定流在超时前将尝试读取的时间。Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

(继承自 Stream)

获取 SafeFileHandle 对象,它代表当前 FileStream 对象所封装的文件的操作系统文件句柄。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.

(继承自 Stream)

方法

关闭当前流并释放与之关联的所有资源(如套接字和文件句柄)。Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.

关闭当前流并释放与之关联的所有资源(如套接字和文件句柄)。Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. 不直接调用此方法,而应确保流得以正确释放。Instead of calling this method, ensure that the stream is properly disposed.

(继承自 Stream)

从当前流中读取字节并将其写入到另一流中。Reads the bytes from the current stream and writes them to another stream.

(继承自 Stream)

使用指定的缓冲区大小,从当前流中读取字节并将其写入到另一流中。Reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(继承自 Stream)

从当前流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current stream and writes them to another stream.

(继承自 Stream)

通过指定的取消令牌,从当前流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token.

(继承自 Stream)

使用指定的缓冲区大小,从当前流中异步读取字节并将其写入到另一流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(继承自 Stream)

使用指定的缓冲区大小和取消令牌,从当前文件流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current file stream and writes them to another stream, using a specified buffer size and cancellation token.

使用指定的缓冲区大小和取消令牌,从当前流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.

(继承自 Stream)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)

释放由 Stream 使用的所有资源。Releases all resources used by the Stream.

(继承自 Stream)

释放由 FileStream 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the FileStream and optionally releases the managed resources.

异步释放 FileStream 使用的非托管资源。Asynchronously releases the unmanaged resources used by the FileStream.

异步释放 Stream 使用的非托管资源。Asynchronously releases the unmanaged resources used by the Stream.

(继承自 Stream)

等待挂起的异步读取完成。Waits for the pending asynchronous read to complete.

(继承自 Stream)

结束异步写入操作,在 I/O 操作完成之前一直阻止。Ends an asynchronous write operation and blocks until the I/O operation is complete.

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

确保垃圾回收器回收 FileStream 时释放资源并执行其他清理操作。Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the FileStream.

清除此流的缓冲区,使得所有缓冲数据都写入到文件中。Clears buffers for this stream and causes any buffered data to be written to the file.

清除此流的缓冲区,将所有缓冲数据都写入到文件中,并且也清除所有中间文件缓冲区。Clears buffers for this stream and causes any buffered data to be written to the file, and also clears all intermediate file buffers.

异步清除此流的所有缓冲区并导致所有缓冲数据都写入基础设备中。Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device.

(继承自 Stream)

异步清理这个流的所有缓冲区,并使所有缓冲数据写入基础设备,并且监控取消请求。Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

异步清理此流的所有缓冲区,导致所有缓冲数据都写入基础设备,并且监控取消请求。Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

(继承自 Stream)

获取 FileSecurity 对象,该对象封装当前 FileStream 对象所描述的文件的访问控制列表 (ACL) 项。Gets a FileSecurity object that encapsulates the access control list (ACL) entries for the file described by the current FileStream object.

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)

获取当前实例的 Type。Gets the Type of the current instance.

(继承自 Object)

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)

防止其他进程读取或写入 FileStream。Prevents other processes from reading from or writing to the FileStream.

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

已过时。

Provides support for a Contract.

(继承自 Stream)

从流中读取字节块并将该数据写入给定缓冲区中。Reads a block of bytes from the stream and writes the data in a given buffer.

从当前文件流中读取字节序列,并在该文件流中按照读取的字节数提升位置。Reads a sequence of bytes from the current file stream and advances the position within the file stream by the number of bytes read.

当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数。When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(继承自 Stream)

从当前流异步读取字节序列,并将流中的位置提升读取的字节数。Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(继承自 Stream)

从当前文件流异步读取字节的序列,将其写入从指定偏移量开始的字节数组,按读取的字节数向前移动文件流中的位置,并监视取消请求。Asynchronously reads a sequence of bytes from the current file stream and writes them to a byte array beginning at a specified offset, advances the position within the file stream by the number of bytes read, and monitors cancellation requests.

从当前流异步读取字节的序列,将流中的位置提升读取的字节数,并监视取消请求。Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(继承自 Stream)

从当前文件流异步读取字节的序列,将其写入某内存区域,按读取的字节数向前移动文件流中的位置,并监视取消请求。Asynchronously reads a sequence of bytes from the current file stream and writes them to a memory region, advances the position within the file stream by the number of bytes read, and monitors cancellation requests.

从当前流异步读取字节的序列,将流中的位置提升读取的字节数,并监视取消请求。Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(继承自 Stream)

从文件中读取一个字节,并将读取位置提升一个字节。Reads a byte from the file and advances the read position one byte.

将该流的当前位置设置为给定值。Sets the current position of this stream to the given value.

将 FileSecurity 对象所描述的访问控制列表 (ACL) 项应用于当前 FileStream 对象所描述的文件。Applies access control list (ACL) entries described by a FileSecurity object to the file described by the current FileStream object.

将该流的长度设置为给定值。Sets the length of this stream to the given value.

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

允许其他进程访问以前锁定的某个文件的全部或部分。Allows access by other processes to all or part of a file that was previously locked.

将字节块写入文件流。Writes a block of bytes to the file stream.

将字节的序列从只读范围写入当前文件流,并按写入的字节数向前移动此文件流中的当前位置。Writes a sequence of bytes from a read-only span to the current file stream and advances the current position within this file stream by the number of bytes written.

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(继承自 Stream)

将字节序列异步写入当前流,并将流的当前位置提升写入的字节数。Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(继承自 Stream)

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(继承自 Stream)

将字节的序列从内存区域异步写入当前文件流,按写入的字节数向前移动该文件流中的当前位置,并监视取消请求。Asynchronously writes a sequence of bytes from a memory region to the current file stream, advances the current position within this file stream by the number of bytes written, and monitors cancellation requests.

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(继承自 Stream)

一个字节写入文件流中的当前位置。Writes a byte to the current position in the file stream.

显式接口实现

释放由 Stream 使用的所有资源。Releases all resources used by the Stream.

(继承自 Stream)

扩展方法

返回文件的安全信息。Returns the security information of a file.

更改现有文件的安全属性。Changes the security attributes of an existing file.

将适用于 Windows 应用商店应用的 .NET 中的托管流转换为 Windows 运行时中的输入流。Converts a managed stream in the .NET for Windows Store apps to an input stream in the Windows Runtime.

将适用于 Windows 应用商店应用的 .NET 中的托管流转换为 Windows 运行时中的输出流。Converts a managed stream in the .NET for Windows Store apps to an output stream in the Windows Runtime.

将指定的流转换为随机访问流。Converts the specified stream to a random access stream.

配置如何执行从异步可处置项返回的任务的等待。Configures how awaits on the tasks returned from an async disposable are performed.

适用于

另请参阅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值