IsolatedStorageFileStream 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 IsolatedStorageFileStream 类的新实例。 打开 an 的唯一 IsolatedStorageFileStream 方法是使用其构造函数之一。
重载
IsolatedStorageFileStream(String, FileMode)
初始化对象的新实例,该实例IsolatedStorageFileStream授予对指定path文件中指定mode文件的访问权限。
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode)
参数
- path
- String
独立存储中文件的相对路径。
例外
格式 path 不正确。
path 是 null。
目录中 path 不存在。
找不到文件,并且 mode 已设置为 Open
注解
使用的隔离存储的范围由当前正在执行的程序集的标识及其在其中运行的应用程序域的标识范围。 此存储仅在 IsolatedStorageFileStream 对象的生命周期内保持打开状态。 若要指定不同的隔离存储范围,或允许存储保持打开状态(因此可从中打开多个 IsolatedStorageFileStream 对象),请使用接受对象的 IsolatedStorageFile 构造函数的形式。
该 mode 参数指示是否应创建新文件、使用的现有文件等。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能不可解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, FileAccess)
使用所请求的类型IsolatedStorageFileStream初始化类的新实例path,以授予对指定mode文件中access指定文件的访问权限。
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::FileAccess access);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.FileAccess -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, access As FileAccess)
参数
- path
- String
独立存储中文件的相对路径。
- access
- FileAccess
值的按位组合 FileAccess 。
例外
格式 path 不正确。
path 是 null。
找不到任何文件,并且 mode 该文件设置为 Open。
注解
使用的隔离存储的范围由当前正在执行的程序集的标识及其在其中运行的应用程序域的标识范围。 此存储仅在 IsolatedStorageFileStream 对象的生命周期内保持打开状态。 若要指定不同的隔离存储范围,或允许存储保持打开状态(因此可从中打开多个 IsolatedStorageFileStream 对象),请使用接受对象的 IsolatedStorageFile 构造函数的形式。
该 mode 参数指示是应创建新文件还是使用现有文件。 该 access 参数包括只读、读/写和仅写。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能无法解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, IsolatedStorageFile)
初始化类的新实例IsolatedStorageFileStream,以授予对指定path文件中mode和指定上下文IsolatedStorageFileisf中指定文件的访问权限。
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::IsolatedStorage::IsolatedStorageFile ^ isf);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.IsolatedStorage.IsolatedStorageFile isf);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.IsolatedStorage.IsolatedStorageFile -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, isf As IsolatedStorageFile)
参数
- path
- String
独立存储中文件的相对路径。
要 IsolatedStorageFile 在其中打开的 IsolatedStorageFileStream。
例外
格式 path 不正确。
path 是 null。
找不到任何文件,并且 mode 该文件设置为 Open。
isf 没有配额。
示例
下面的代码示例演示如何使用此构造函数。 有关此示例的完整上下文,请参阅 IsolatedStorageFileStream 概述。
IsolatedStorageFileStream source =
new IsolatedStorageFileStream(this.userName, FileMode.OpenOrCreate,
isoFile);
// This is the stream from which data will be read.
Console.WriteLine("Is the source file readable? " + (source.CanRead ? "true" : "false"));
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.");
// Open or create a writable file.
IsolatedStorageFileStream target =
new IsolatedStorageFileStream("Archive\\ " + this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
isoFile);
' Open or create a writable file.
Dim target As New IsolatedStorageFileStream("Archive\ " & Me.userName, _
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoFile)
注解
该 mode 参数指示是否应创建新文件、使用的现有文件等。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能无法解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare)
使用指定的文件共享模式初始化类的新实例IsolatedStorageFileStream,以使用指定的文件访问指定的文件pathmodeaccess。share
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::FileAccess access, System::IO::FileShare share);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, access As FileAccess, share As FileShare)
参数
- path
- String
独立存储中文件的相对路径。
- access
- FileAccess
值的按位组合 FileAccess 。
例外
格式 path 不正确。
path 是 null。
找不到任何文件,并且 mode 该文件设置为 Open。
示例
下面的代码示例演示如何使用此构造函数。 有关此示例的完整上下文,请参阅 IsolatedStorageFileStream 概述。
// Retrieve an IsolatedStorageFile for the current Domain and Assembly.
IsolatedStorageFile isoFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
null,
null);
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream("substituteUsername",
System.IO.FileMode.Open,
System.IO.FileAccess.Read,
System.IO.FileShare.Read);
' Retrieve an IsolatedStorageFile for the current Domain and Assembly.
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetStore(IsolatedStorageScope.User _
Or IsolatedStorageScope.Assembly _
Or IsolatedStorageScope.Domain, Nothing, Nothing)
Dim isoStream As New IsolatedStorageFileStream("substituteUsername", System.IO.FileMode.Open, _
System.IO.FileAccess.Read, System.IO.FileShare.Read)
注解
使用的隔离存储的范围由当前正在执行的程序集的标识及其在其中运行的应用程序域的标识范围。 此存储仅在 IsolatedStorageFileStream 对象的生命周期内保持打开状态。 若要指定不同的隔离存储范围,或允许存储保持打开状态(因此可从中打开多个 IsolatedStorageFileStream 对象),请使用接受对象的 IsolatedStorageFile 构造函数的形式。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能不可解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, FileAccess, IsolatedStorageFile)
使用指定的IsolatedStorageFileStream文件,并在指定的path上下文mode中初始化类的新实例access,以访问指定的IsolatedStorageFile文件isf。
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::FileAccess access, System::IO::IsolatedStorage::IsolatedStorageFile ^ isf);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.IsolatedStorage.IsolatedStorageFile isf);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.FileAccess * System.IO.IsolatedStorage.IsolatedStorageFile -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, access As FileAccess, isf As IsolatedStorageFile)
参数
- path
- String
独立存储中文件的相对路径。
- access
- FileAccess
值的按位组合 FileAccess 。
要 IsolatedStorageFile 在其中打开的 IsolatedStorageFileStream。
例外
格式 path 不正确。
path 是 null。
隔离存储已关闭。
找不到任何文件,并且 mode 该文件设置为 Open。
isf 没有配额。
示例
下面的代码示例演示如何使用此构造函数。 有关此示例的完整上下文,请参阅 IsolatedStorageFileStream 概述。
IsolatedStorageFile isoFile;
isoFile = IsolatedStorageFile.GetUserStoreForDomain();
// Open or create a writable file.
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream(this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
isoFile);
StreamWriter writer = new StreamWriter(isoStream);
writer.WriteLine(this.NewsUrl);
writer.WriteLine(this.SportsUrl);
// Calculate the amount of space used to record the user's preferences.
double d = isoFile.CurrentSize / isoFile.MaximumSize;
Console.WriteLine("CurrentSize = " + isoFile.CurrentSize.ToString());
Console.WriteLine("MaximumSize = " + isoFile.MaximumSize.ToString());
// StreamWriter.Close implicitly closes isoStream.
writer.Close();
isoFile.Dispose();
isoFile.Close();
return d;
Dim isoFile As IsolatedStorageFile
isoFile = IsolatedStorageFile.GetUserStoreForDomain()
' Open or create a writable file.
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, _
FileAccess.Write, isoFile)
Dim writer As New StreamWriter(isoStream)
writer.WriteLine(Me.NewsUrl)
writer.WriteLine(Me.SportsUrl)
' Calculate the amount of space used to record the user's preferences.
Dim d As Double = Convert.ToDouble(isoFile.CurrentSize) / Convert.ToDouble(isoFile.MaximumSize)
Console.WriteLine(("CurrentSize = " & isoFile.CurrentSize.ToString()))
Console.WriteLine(("MaximumSize = " & isoFile.MaximumSize.ToString()))
' StreamWriter.Close implicitly closes isoStream.
writer.Close()
isoFile.Dispose()
isoFile.Close()
Return d
注解
该 mode 参数指示是应创建新文件还是使用现有文件。 该 access 参数包括只读、读/写和仅写。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能无法解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, Int32)
使用指定的文件共享模式IsolatedStorageFileStreampath,使用指定的mode文件初始化类的新实例access,以访问指定文件中指定的share文件bufferSize。
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::FileAccess access, System::IO::FileShare share, int bufferSize);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare * int -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, access As FileAccess, share As FileShare, bufferSize As Integer)
参数
- path
- String
独立存储中文件的相对路径。
- access
- FileAccess
值的按位组合 FileAccess 。
- bufferSize
- Int32
FileStream缓冲区大小。
例外
格式 path 不正确。
path 是 null。
找不到任何文件,并且 mode 该文件设置为 Open。
注解
使用的隔离存储的范围由当前正在执行的程序集的标识及其在其中运行的应用程序域的标识范围。 此存储仅在 IsolatedStorageFileStream 对象的生命周期内保持打开状态。 若要指定不同的隔离存储范围,或允许存储保持打开状态(因此可从中打开多个 IsolatedStorageFileStream 对象),请使用接受对象的 IsolatedStorageFile 构造函数的形式。
该 mode 参数指示是应创建新文件还是使用现有文件。 该 access 参数包括只读、读/写和仅写。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能无法解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, IsolatedStorageFile)
使用指定的文件共享模式IsolatedStorageFileStream,并在指定的上下文pathmode中,使用指定的access文件share初始化类的新实例IsolatedStorageFile,以访问指定的文件isf。
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::FileAccess access, System::IO::FileShare share, System::IO::IsolatedStorage::IsolatedStorageFile ^ isf);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.IO.IsolatedStorage.IsolatedStorageFile isf);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare * System.IO.IsolatedStorage.IsolatedStorageFile -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, access As FileAccess, share As FileShare, isf As IsolatedStorageFile)
参数
- path
- String
独立存储中文件的相对路径。
- access
- FileAccess
值的按位组合 FileAccess 。
要 IsolatedStorageFile 在其中打开的 IsolatedStorageFileStream。
例外
格式 path 不正确。
path 是 null。
找不到任何文件,并且 mode 该文件设置为 Open。
isf 没有配额。
示例
下面的代码示例演示如何使用此构造函数。 有关此示例的完整上下文,请参阅 IsolatedStorageFileStream 概述。
IsolatedStorageFileStream source =
new IsolatedStorageFileStream(this.userName, FileMode.OpenOrCreate,
isoFile);
// This is the stream from which data will be read.
Console.WriteLine("Is the source file readable? " + (source.CanRead ? "true" : "false"));
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.");
// Open or create a writable file.
IsolatedStorageFileStream target =
new IsolatedStorageFileStream("Archive\\ " + this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
isoFile);
' Open or create a writable file.
Dim target As New IsolatedStorageFileStream("Archive\ " & Me.userName, _
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoFile)
注解
该 mode 参数指示是应创建新文件还是使用现有文件。 该 access 参数包括只读、读/写和仅写。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能无法解释,并可能导致引发异常。
适用于
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, Int32, IsolatedStorageFile)
初始化类的新实例,以指定方式使用指定文件访问指定的文件IsolatedStorageFileStreampath,使用指定的文件共享模式modeaccess、指定的、指定的上下文以及指定的上下文来初始化该share类的新实例bufferSizeIsolatedStorageFile。isf
public:
IsolatedStorageFileStream(System::String ^ path, System::IO::FileMode mode, System::IO::FileAccess access, System::IO::FileShare share, int bufferSize, System::IO::IsolatedStorage::IsolatedStorageFile ^ isf);
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.IsolatedStorage.IsolatedStorageFile isf);
new System.IO.IsolatedStorage.IsolatedStorageFileStream : string * System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare * int * System.IO.IsolatedStorage.IsolatedStorageFile -> System.IO.IsolatedStorage.IsolatedStorageFileStream
Public Sub New (path As String, mode As FileMode, access As FileAccess, share As FileShare, bufferSize As Integer, isf As IsolatedStorageFile)
参数
- path
- String
独立存储中文件的相对路径。
- access
- FileAccess
值的按位组合 FileAccess 。
- bufferSize
- Int32
FileStream缓冲区大小。
要 IsolatedStorageFile 在其中打开的 IsolatedStorageFileStream。
例外
格式 path 不正确。
path 是 null。
找不到任何文件,并且 mode 该文件设置为 Open。
isf 没有配额。
示例
下面的代码示例演示如何使用此构造函数。 有关此示例的完整上下文,请参阅 IsolatedStorageFileStream 概述。
// Open or create a writable file with a maximum size of 10K.
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream(this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
10240,
isoFile);
' Open or create a writable file with a maximum size of 10K.
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, _
FileAccess.Write, FileShare.Write, 10240, isoFile)
注解
该 mode 参数指示是应创建新文件还是使用现有文件。 该 access 参数包括只读、读/写和仅写。
Caution
使用特定区域性设置编译一组字符并检索具有不同区域性设置的相同字符时,这些字符可能无法解释,并可能导致引发异常。