IsolatedStorageFileStream Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengekspos file dalam penyimpanan terisolasi.
public ref class IsolatedStorageFileStream : System::IO::Stream
public ref class IsolatedStorageFileStream : System::IO::FileStream
public class IsolatedStorageFileStream : System.IO.Stream
public class IsolatedStorageFileStream : System.IO.FileStream
[System.Runtime.InteropServices.ComVisible(true)]
public class IsolatedStorageFileStream : System.IO.FileStream
type IsolatedStorageFileStream = class
inherit Stream
type IsolatedStorageFileStream = class
inherit FileStream
[<System.Runtime.InteropServices.ComVisible(true)>]
type IsolatedStorageFileStream = class
inherit FileStream
Public Class IsolatedStorageFileStream
Inherits Stream
Public Class IsolatedStorageFileStream
Inherits FileStream
- Warisan
- Warisan
- Atribut
Contoh
Aplikasi konsol berikut menunjukkan bagaimana Anda dapat menggunakan IsolatedStorageFile dan IsolatedStorageFileStream menulis data ke file Penyimpanan Terisolasi. Pengguna diminta untuk masuk. Jika pengguna adalah pengguna baru, URL Berita dan URL Olahraga dicatat sebagai preferensi pribadi di Penyimpanan Terisolasi. Jika pengguna adalah pengguna yang kembali, preferensi pengguna saat ini akan ditampilkan. Contoh kode yang digunakan di seluruh namespace ini disajikan dalam konteks aplikasi sampel ini. Anda dapat menggunakan utilitas Storeadm.exe (Alat Penyimpanan Terisolasi) untuk mencantumkan dan menghapus file Penyimpanan Terisolasi yang dibuat dengan aplikasi konsol ini.
// This sample demonstrates methods of classes found in the System.IO IsolatedStorage namespace.
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Security.Policy;
using Microsoft.Win32.SafeHandles;
[assembly: CLSCompliantAttribute(true)]
class ConsoleApp
{
[STAThread]
static void Main(string[] args)
{
// Prompt the user for their username.
Console.WriteLine("Login:");
// Does no error checking.
LoginPrefs lp = new LoginPrefs(Console.ReadLine());
if (lp.NewPrefs)
{
Console.WriteLine("Please set preferences for a new user.");
GatherInfoFromUser(lp);
// Write the new preferences to storage.
double percentUsed = lp.SetPrefsForUser();
Console.WriteLine("Your preferences have been written. Current space used is " + percentUsed.ToString() + " %");
}
else
{
Console.WriteLine("Welcome back.");
Console.WriteLine("Your preferences have expired, please reset them.");
GatherInfoFromUser(lp);
lp.SetNewPrefsForUser();
Console.WriteLine("Your news site has been set to {0}\n and your sports site has been set to {1}.", lp.NewsUrl, lp.SportsUrl);
}
lp.GetIsoStoreInfo();
Console.WriteLine("Enter 'd' to delete the IsolatedStorage files and exit, or press any other key to exit without deleting files.");
string consoleInput = Console.ReadLine();
if (consoleInput.ToLower() == "d")
{
lp.DeleteFiles();
lp.DeleteDirectories();
}
}
static void GatherInfoFromUser(LoginPrefs lp)
{
Console.WriteLine("Please enter the URL of your news site.");
lp.NewsUrl = Console.ReadLine();
Console.WriteLine("Please enter the URL of your sports site.");
lp.SportsUrl = Console.ReadLine();
}
}
public class LoginPrefs
{
public LoginPrefs(string myUserName)
{
userName = myUserName;
myNewPrefs = GetPrefsForUser();
}
string userName;
string myNewsUrl;
public string NewsUrl
{
get { return myNewsUrl; }
set { myNewsUrl = value; }
}
string mySportsUrl;
public string SportsUrl
{
get { return mySportsUrl; }
set { mySportsUrl = value; }
}
bool myNewPrefs;
public bool NewPrefs
{
get { return myNewPrefs; }
}
private bool GetPrefsForUser()
{
try
{
// 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);
// The code executes to this point only if a file corresponding to the username exists.
// Though you can perform operations on the stream, you cannot get a handle to the file.
try
{
SafeFileHandle aFileHandle = isoStream.SafeFileHandle;
Console.WriteLine("A pointer to a file handle has been obtained. "
+ aFileHandle.ToString() + " "
+ aFileHandle.GetHashCode());
}
catch (Exception e)
{
// Handle the exception.
Console.WriteLine("Expected exception");
Console.WriteLine(e);
}
StreamReader reader = new StreamReader(isoStream);
// Read the data.
this.NewsUrl = reader.ReadLine();
this.SportsUrl = reader.ReadLine();
reader.Close();
isoFile.Close();
return false;
}
catch (System.IO.FileNotFoundException)
{
// Expected exception if a file cannot be found. This indicates that we have a new user.
return true;
}
}
public bool GetIsoStoreInfo()
{
// Get a User store with type evidence for the current Domain and the Assembly.
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("*");
// List directories currently in this Isolated Storage.
if (dirNames.Length > 0)
{
for (int i = 0; i < dirNames.Length; ++i)
{
Console.WriteLine("Directory Name: " + dirNames[i]);
}
}
// List the files currently in this Isolated Storage.
// The list represents all users who have personal preferences stored for this application.
if (fileNames.Length > 0)
{
for (int i = 0; i < fileNames.Length; ++i)
{
Console.WriteLine("File Name: " + fileNames[i]);
}
}
isoFile.Close();
return true;
}
public double SetPrefsForUser()
{
try
{
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;
}
catch (IsolatedStorageException ex)
{
// Add code here to handle the exception.
Console.WriteLine(ex);
return 0.0;
}
}
public void DeleteFiles()
{
try
{
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("*");
// List the files currently in this Isolated Storage.
// The list represents all users who have personal
// preferences stored for this application.
if (fileNames.Length > 0)
{
for (int i = 0; i < fileNames.Length; ++i)
{
// Delete the files.
isoFile.DeleteFile(fileNames[i]);
}
// Confirm that no files remain.
fileNames = isoFile.GetFileNames("*");
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
// This method deletes directories in the specified Isolated Storage, after first
// deleting the files they contain. In this example, the Archive directory is deleted.
// There should be no other directories in this Isolated Storage.
public void DeleteDirectories()
{
try
{
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("Archive\\*");
// Delete all the files currently in the Archive directory.
if (fileNames.Length > 0)
{
for (int i = 0; i < fileNames.Length; ++i)
{
// Delete the files.
isoFile.DeleteFile("Archive\\" + fileNames[i]);
}
// Confirm that no files remain.
fileNames = isoFile.GetFileNames("Archive\\*");
}
if (dirNames.Length > 0)
{
for (int i = 0; i < dirNames.Length; ++i)
{
// Delete the Archive directory.
}
}
dirNames = isoFile.GetDirectoryNames("*");
isoFile.Remove();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public double SetNewPrefsForUser()
{
try
{
byte inputChar;
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
// If this is not a new user, archive the old preferences and
// overwrite them using the new preferences.
if (!this.myNewPrefs)
{
if (isoFile.GetDirectoryNames("Archive").Length == 0)
{
isoFile.CreateDirectory("Archive");
}
else
{
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);
Console.WriteLine("Is the target file writable? " + (target.CanWrite ? "true" : "false"));
// Stream the old file to a new file in the Archive directory.
if (source.IsAsync && target.IsAsync)
{
// IsolatedStorageFileStreams cannot be asynchronous. However, you
// can use the asynchronous BeginRead and BeginWrite functions
// with some possible performance penalty.
Console.WriteLine("IsolatedStorageFileStreams cannot be asynchronous.");
}
else
{
Console.WriteLine("Writing data to the new file.");
while (source.Position < source.Length)
{
inputChar = (byte)source.ReadByte();
target.WriteByte(inputChar);
}
// Determine the size of the IsolatedStorageFileStream
// by checking its Length property.
Console.WriteLine("Total Bytes Read: " + source.Length);
}
// After you have read and written to the streams, close them.
target.Close();
source.Close();
}
}
// 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);
isoStream.Position = 0; // Position to overwrite the old data.
StreamWriter writer = new StreamWriter(isoStream);
// Update the data based on the new inputs.
writer.WriteLine(this.NewsUrl);
writer.WriteLine(this.SportsUrl);
// Calculate the amount of space used to record this 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.Close();
return d;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return 0.0;
}
}
}
'This sample demonstrates methods of classes found in the System.IO IsolatedStorage namespace.
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Security.Policy
Imports Microsoft.Win32.SafeHandles
Imports System.Security.Permissions
Namespace ISOCS
_
Class ConsoleApp
<STAThread()> _
Overloads Shared Sub Main(ByVal args() As String)
' Prompt the user for their username.
Console.WriteLine("Enter your login ID:")
' Does no error checking.
Dim lp As New LoginPrefs(Console.ReadLine())
If lp.NewPrefs Then
Console.WriteLine("Please set preferences for a new user.")
GatherInfoFromUser(lp)
' Write the new preferences to storage.
Dim percentUsed As Double = lp.SetPrefsForUser()
Console.WriteLine(("Your preferences have been written. Current space used is " & percentUsed.ToString() & " %"))
Else
Console.WriteLine("Welcome back.")
Console.WriteLine("Your preferences have expired, please reset them.")
GatherInfoFromUser(lp)
lp.SetNewPrefsForUser()
Console.WriteLine("Your news site has been set to {0}" & ControlChars.Cr & " and your sports site has been set to {1}.", lp.NewsUrl, lp.SportsUrl)
End If
lp.GetIsoStoreInfo()
Console.WriteLine("Enter 'd' to delete the IsolatedStorage files and exit, or press any other key to exit without deleting files.")
Dim consoleInput As String = Console.ReadLine()
If consoleInput.ToLower() = "d" Then
lp.DeleteFiles()
lp.DeleteDirectories()
End If
End Sub
Shared Sub GatherInfoFromUser(ByVal lp As LoginPrefs)
Console.WriteLine("Please enter the URL of your news site.")
lp.NewsUrl = Console.ReadLine()
Console.WriteLine("Please enter the URL of your sports site.")
lp.SportsUrl = Console.ReadLine()
End Sub
End Class
_
<SecurityPermissionAttribute(SecurityAction.Demand, Flags:=SecurityPermissionFlag.UnmanagedCode)> _
Public Class LoginPrefs
Public Sub New(ByVal myUserName As String)
userName = myUserName
myNewPrefs = GetPrefsForUser()
End Sub
Private userName As String
Private myNewsUrl As String
Public Property NewsUrl() As String
Get
Return myNewsUrl
End Get
Set(ByVal Value As String)
myNewsUrl = Value
End Set
End Property
Private mySportsUrl As String
Public Property SportsUrl() As String
Get
Return mySportsUrl
End Get
Set(ByVal Value As String)
mySportsUrl = Value
End Set
End Property
Private myNewPrefs As Boolean
Public ReadOnly Property NewPrefs() As Boolean
Get
Return myNewPrefs
End Get
End Property
Private Function GetPrefsForUser() As Boolean
Try
' 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)
' farThe code executes to this point only if a file corresponding to the username exists.
' Though you can perform operations on the stream, you cannot get a handle to the file.
Try
Dim aFileHandle As SafeFileHandle = isoStream.SafeFileHandle
Console.WriteLine(("A pointer to a file handle has been obtained. " & aFileHandle.ToString() & " " & aFileHandle.GetHashCode()))
Catch ex As Exception
' Handle the exception.
Console.WriteLine("Expected exception")
Console.WriteLine(ex.ToString())
End Try
Dim reader As New StreamReader(isoStream)
' Read the data.
Me.NewsUrl = reader.ReadLine()
Me.SportsUrl = reader.ReadLine()
reader.Close()
isoFile.Close()
Return False
Catch ex As System.IO.FileNotFoundException
' Expected exception if a file cannot be found. This indicates that we have a new user.
Return True
End Try
End Function 'GetPrefsForUser
Public Function GetIsoStoreInfo() As Boolean
Try
'Get a User store with type evidence for the current Domain and the Assembly.
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("*")
Dim name As String
' List directories currently in this Isolated Storage.
If dirNames.Length > 0 Then
For Each name In dirNames
Console.WriteLine("Directory Name: " & name)
Next name
End If
' List the files currently in this Isolated Storage.
' The list represents all users who have personal preferences stored for this application.
If fileNames.Length > 0 Then
For Each name In fileNames
Console.WriteLine("File Name: " & name)
Next name
End If
isoFile.Close()
Return True
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Function 'GetIsoStoreInfo
Public Function SetPrefsForUser() As Double
Try
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
Catch ex As Exception
' Add code here to handle the exception.
Console.WriteLine(ex)
Return 0.0
End Try
End Function 'SetPrefsForUser
Public Sub DeleteFiles()
Try
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
Dim name As String
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("*")
' List the files currently in this Isolated Storage.
' The list represents all users who have personal
' preferences stored for this application.
If fileNames.Length > 0 Then
For Each name In fileNames
' Delete the files.
isoFile.DeleteFile(name)
Next name
'Confirm no files are left.
fileNames = isoFile.GetFileNames("*")
End If
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Sub
' This method deletes directories in the specified Isolated Storage, after first
' deleting the files they contain. In this example, the Archive directory is deleted.
' There should be no other directories in this Isolated Storage.
Public Sub DeleteDirectories()
Try
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User _
Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
Dim name As String
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("Archive\*")
' Delete all the files currently in the Archive directory.
If fileNames.Length > 0 Then
For Each name In fileNames
isoFile.DeleteFile(("Archive\" & name))
Next name
'Confirm no files are left.
fileNames = isoFile.GetFileNames("Archive\*")
End If
If dirNames.Length > 0 Then
For Each name In dirNames
' Delete the Archive directory.
isoFile.DeleteDirectory(name)
Next name
End If
dirNames = isoFile.GetDirectoryNames("*")
isoFile.Remove()
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Sub
Public Function SetNewPrefsForUser() As Double
Try
Dim inputChar As Byte
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
' If this is not a new user, archive the old preferences and
' overwrite them using the new preferences.
If Not Me.myNewPrefs Then
If isoFile.GetDirectoryNames("Archive").Length = 0 Then
isoFile.CreateDirectory("Archive")
Else
Dim source As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, isoFile)
Dim canWrite, canRead As Boolean
' This is the stream from which data will be read.
If source.CanRead Then canRead = True Else canRead = False
Console.WriteLine("Is the source file readable? " & canRead)
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.")
' Open or create a writable file.
Dim target As New IsolatedStorageFileStream("Archive\ " & Me.userName, _
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoFile)
' This is the stream to which data will be written.
If target.CanWrite Then canWrite = True Else canWrite = False
Console.WriteLine("Is the target file writable? " & canWrite)
target.SetLength(0) 'rewind the target file
' Stream the old file to a new file in the Archive directory.
If source.IsAsync And target.IsAsync Then
' IsolatedStorageFileStreams cannot be asynchronous. However, you
' can use the asynchronous BeginRead and BeginWrite functions
' with some possible performance penalty.
Console.WriteLine("IsolatedStorageFileStreams cannot be asynchronous.")
Else
Console.WriteLine("Writing data to the new file.")
While source.Position < source.Length
inputChar = CByte(source.ReadByte())
target.WriteByte(inputChar)
End While
' Determine the size of the IsolatedStorageFileStream
' by checking its Length property.
Console.WriteLine(("Total Bytes Read: " & source.Length))
End If
' After you have read and written to the streams, close them.
target.Close()
source.Close()
End If
End If
' 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)
isoStream.SetLength(0) 'Position to overwrite the old data.
Dim writer As New StreamWriter(isoStream)
' Update the data based on the new inputs.
writer.WriteLine(Me.NewsUrl)
writer.WriteLine(Me.SportsUrl)
' Calculate the amount of space used to record this 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.Close()
Return d
Catch ex As Exception
Console.WriteLine(ex.ToString())
Return 0.0
End Try
End Function 'SetNewPrefsForUser
End Class
End Namespace 'ISOCS
Keterangan
Gunakan kelas ini untuk membaca, menulis, dan membuat file di penyimpanan terisolasi.
Karena kelas ini meluas FileStream, Anda dapat menggunakan instans IsolatedStorageFileStream dalam sebagian besar situasi di mana FileStream mungkin digunakan, seperti untuk membangun StreamReader atau StreamWriter.
Jenis ini mengimplementasikan antarmuka IDisposable. Setelah selesai menggunakan jenisnya, Anda harus membuangnya baik secara langsung maupun tidak langsung. Untuk meniadakan tipe secara langsung, panggil metode Dispose dalam blok try/catch. Untuk membuangnya secara tidak langsung, gunakan konstruksi bahasa seperti using (dalam C#) atau Using (di Visual Basic). Untuk informasi selengkapnya, lihat bagian "Menggunakan Objek yang Menerapkan IDisposable" dalam IDisposable topik antarmuka.
Konstruktor
| Nama | Deskripsi |
|---|---|
| IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, Int32, IsolatedStorageFile) |
Menginisialisasi instans IsolatedStorageFileStream baru kelas yang memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, Int32) |
Menginisialisasi instans IsolatedStorageFileStream baru kelas yang memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, IsolatedStorageFile) |
Menginisialisasi instans IsolatedStorageFileStream baru kelas yang memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare) |
Menginisialisasi instans IsolatedStorageFileStream baru kelas yang memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode, FileAccess, IsolatedStorageFile) |
Menginisialisasi instans IsolatedStorageFileStream baru kelas yang memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode, FileAccess) |
Menginisialisasi instans baru kelas yang IsolatedStorageFileStream memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode, IsolatedStorageFile) |
Menginisialisasi instans IsolatedStorageFileStream baru kelas yang memberikan akses ke file yang ditunjuk oleh |
| IsolatedStorageFileStream(String, FileMode) |
Menginisialisasi instans baru objek yang IsolatedStorageFileStream memberikan akses ke file yang ditunjuk oleh |
Properti
| Nama | Deskripsi |
|---|---|
| CanRead |
Mendapatkan nilai Boolean yang menunjukkan apakah file dapat dibaca. |
| CanSeek |
Mendapatkan nilai Boolean yang menunjukkan apakah operasi pencarian didukung. |
| CanTimeout |
Mendapatkan nilai yang menentukan apakah aliran saat ini dapat kehabisan waktu. (Diperoleh dari Stream) |
| CanWrite |
Mendapatkan nilai Boolean yang menunjukkan apakah Anda dapat menulis ke file. |
| Handle |
Kedaluwarsa.
Kedaluwarsa.
Kedaluwarsa.
Mendapatkan handel file untuk file yang dienkapsulasi objek saat ini IsolatedStorageFileStream . Mengakses properti ini tidak diizinkan pada objekIsolatedStorageFileStream, dan melempar .IsolatedStorageException |
| IsAsync |
Mendapatkan nilai Boolean yang menunjukkan apakah IsolatedStorageFileStream objek dibuka secara asinkron atau sinkron. |
| Length |
Mendapatkan panjang IsolatedStorageFileStream objek. |
| Name |
Mendapatkan jalur absolut file yang dibuka di |
| Position |
Mendapatkan atau mengatur posisi objek saat ini IsolatedStorageFileStream . |
| ReadTimeout |
Mendapatkan atau menetapkan nilai, dalam milidetik, yang menentukan berapa lama aliran akan mencoba membaca sebelum waktu habis. (Diperoleh dari Stream) |
| SafeFileHandle |
SafeFileHandle Mendapatkan objek yang mewakili handel file sistem operasi untuk file yang dienkapsulasi objek saat iniIsolatedStorageFileStream. |
| WriteTimeout |
Mendapatkan atau menetapkan nilai, dalam milidetik, yang menentukan berapa lama aliran akan mencoba menulis sebelum waktu habis. (Diperoleh dari Stream) |
Metode
| Nama | Deskripsi |
|---|---|
| BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) |
Memulai bacaan asinkron. |
| BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) |
Memulai penulisan asinkron. |
| Close() |
Merilis sumber daya yang terkait dengan IsolatedStorageFileStream objek. |
| CopyTo(Stream, Int32) |
Membaca byte dari aliran saat ini dan menulisnya ke aliran lain, menggunakan ukuran buffer tertentu. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari Stream) |
| CopyTo(Stream, Int32) |
Membaca byte dari aliran saat ini dan menulisnya ke aliran lain, menggunakan ukuran buffer tertentu. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari FileStream) |
| CopyTo(Stream) |
Membaca byte dari aliran saat ini dan menulisnya ke aliran lain. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari Stream) |
| CopyToAsync(Stream, CancellationToken) |
Secara asinkron membaca byte dari aliran saat ini dan menulisnya ke aliran lain, menggunakan token pembatalan tertentu. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari Stream) |
| CopyToAsync(Stream, Int32, CancellationToken) |
Secara asinkron membaca byte dari aliran saat ini dan menulisnya ke aliran lain, menggunakan ukuran buffer dan token pembatalan yang ditentukan. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari Stream) |
| CopyToAsync(Stream, Int32, CancellationToken) |
Secara asinkron membaca byte dari aliran file saat ini dan menulisnya ke aliran lain, menggunakan ukuran buffer dan token pembatalan yang ditentukan. (Diperoleh dari FileStream) |
| CopyToAsync(Stream, Int32) |
Secara asinkron membaca byte dari aliran saat ini dan menulisnya ke aliran lain, menggunakan ukuran buffer tertentu. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari Stream) |
| CopyToAsync(Stream) |
Secara asinkron membaca byte dari aliran saat ini dan menulisnya ke aliran lain. Kedua posisi aliran dimajukan dengan jumlah byte yang disalin. (Diperoleh dari Stream) |
| CreateObjRef(Type) |
Membuat objek yang berisi semua informasi relevan yang diperlukan untuk menghasilkan proksi yang digunakan untuk berkomunikasi dengan objek jarak jauh. (Diperoleh dari MarshalByRefObject) |
| CreateWaitHandle() |
Kedaluwarsa.
Kedaluwarsa.
Kedaluwarsa.
Mengalokasikan WaitHandle objek. (Diperoleh dari Stream) |
| Dispose() |
Merilis semua sumber daya yang Streamdigunakan oleh . (Diperoleh dari Stream) |
| Dispose(Boolean) |
Merilis sumber daya yang tidak dikelola yang IsolatedStorageFileStream digunakan oleh dan secara opsional merilis sumber daya terkelola. |
| DisposeAsync() |
Secara asinkron merilis sumber daya yang tidak dikelola yang digunakan oleh IsolatedStorageFileStream. |
| EndRead(IAsyncResult) |
Mengakhiri permintaan baca asinkron yang tertunda. |
| EndWrite(IAsyncResult) |
Mengakhiri penulisan asinkron. |
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| Flush() |
Menghapus buffer untuk aliran ini dan menyebabkan data buffer ditulis ke file. |
| Flush(Boolean) |
Menghapus buffer untuk aliran ini dan menyebabkan data buffer ditulis ke file, dan juga menghapus semua buffer file perantara. |
| FlushAsync() |
Secara asinkron menghapus semua buffer untuk aliran ini dan menyebabkan data yang di-buffer ditulis ke perangkat yang mendasar. (Diperoleh dari Stream) |
| FlushAsync(CancellationToken) |
Secara asinkron menghapus buffer untuk aliran ini dan menyebabkan data yang di-buffer ditulis ke file. |
| FlushAsync(CancellationToken) |
Secara asinkron menghapus semua buffer untuk aliran ini, menyebabkan data yang di-buffer ditulis ke file, dan memantau permintaan pembatalan. (Diperoleh dari FileStream) |
| GetAccessControl() |
FileSecurity Mendapatkan objek yang merangkum entri daftar kontrol akses (ACL) untuk file yang dijelaskan oleh objek saat iniFileStream. (Diperoleh dari FileStream) |
| GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
| GetLifetimeService() |
Kedaluwarsa.
Mengambil objek layanan seumur hidup saat ini yang mengontrol kebijakan seumur hidup untuk instans ini. (Diperoleh dari MarshalByRefObject) |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| InitializeLifetimeService() |
Kedaluwarsa.
Mendapatkan objek layanan seumur hidup untuk mengontrol kebijakan seumur hidup untuk instans ini. (Diperoleh dari MarshalByRefObject) |
| Lock(Int64, Int64) |
Mencegah proses lain membaca dari atau menulis ke aliran. |
| Lock(Int64, Int64) |
Mencegah proses lain membaca dari atau menulis ke FileStream. (Diperoleh dari FileStream) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| MemberwiseClone(Boolean) |
Membuat salinan dangkal objek saat ini MarshalByRefObject . (Diperoleh dari MarshalByRefObject) |
| ObjectInvariant() |
Kedaluwarsa.
Menyediakan dukungan untuk Contract. (Diperoleh dari Stream) |
| Read(Byte[], Int32, Int32) |
Menyalin byte dari objek buffer IsolatedStorageFileStream saat ini ke array byte. |
| Read(Span<Byte>) |
Menyalin byte dari objek buffer IsolatedStorageFileStream saat ini ke rentang byte. |
| ReadAsync(Byte[], Int32, Int32, CancellationToken) |
Menyalin byte secara asinkron dari objek buffer IsolatedStorageFileStream saat ini ke array byte. |
| ReadAsync(Byte[], Int32, Int32, CancellationToken) |
Secara asinkron membaca urutan byte dari aliran file saat ini dan menulisnya ke array byte yang dimulai pada offset tertentu, memajukan posisi dalam aliran file dengan jumlah byte yang dibaca, dan memantau permintaan pembatalan. (Diperoleh dari FileStream) |
| ReadAsync(Byte[], Int32, Int32) |
Secara asinkron membaca urutan byte dari aliran saat ini dan memajukan posisi dalam aliran dengan jumlah byte yang dibaca. (Diperoleh dari Stream) |
| ReadAsync(Memory<Byte>, CancellationToken) |
Menyalin byte secara asinkron dari objek buffer IsolatedStorageFileStream saat ini ke rentang memori byte. |
| ReadAtLeast(Span<Byte>, Int32, Boolean) |
Membaca setidaknya jumlah minimum byte dari aliran saat ini dan memajukan posisi dalam aliran dengan jumlah byte yang dibaca. (Diperoleh dari Stream) |
| ReadAtLeastAsync(Memory<Byte>, Int32, Boolean, CancellationToken) |
Secara asinkron membaca setidaknya jumlah minimum byte dari aliran saat ini, memajukan posisi dalam aliran dengan jumlah byte yang dibaca, dan memantau permintaan pembatalan. (Diperoleh dari Stream) |
| ReadByte() |
Membaca byte tunggal dari IsolatedStorageFileStream objek dalam penyimpanan terisolasi. |
| ReadExactly(Byte[], Int32, Int32) |
|
| ReadExactly(Span<Byte>) |
Membaca byte dari aliran saat ini dan memajukan posisi dalam aliran hingga |
| ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken) |
Secara asinkron membaca |
| ReadExactlyAsync(Memory<Byte>, CancellationToken) |
Membaca byte secara asinkron dari aliran saat ini, memajukan posisi dalam aliran hingga |
| Seek(Int64, SeekOrigin) |
Mengatur posisi objek ini saat ini IsolatedStorageFileStream ke nilai yang ditentukan. |
| SetAccessControl(FileSecurity) |
Menerapkan entri daftar kontrol akses (ACL) yang FileSecurity dijelaskan oleh objek ke file yang dijelaskan oleh objek saat ini FileStream . (Diperoleh dari FileStream) |
| SetLength(Int64) |
Mengatur panjang objek ini IsolatedStorageFileStream ke yang ditentukan |
| ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
| Unlock(Int64, Int64) |
Memungkinkan proses lain mengakses semua atau sebagian file yang sebelumnya dikunci. |
| Unlock(Int64, Int64) |
Memungkinkan akses oleh proses lain ke semua atau sebagian file yang sebelumnya dikunci. (Diperoleh dari FileStream) |
| Write(Byte[], Int32, Int32) |
Menulis blok byte ke objek aliran file penyimpanan terisolasi menggunakan data yang dibaca dari buffer yang terdiri dari array byte. |
| Write(ReadOnlySpan<Byte>) |
Menulis blok byte ke objek aliran file penyimpanan terisolasi menggunakan data yang dibaca dari buffer yang terdiri dari rentang byte baca-saja. |
| WriteAsync(Byte[], Int32, Int32, CancellationToken) |
Secara asinkron menulis blok byte ke objek aliran file penyimpanan terisolasi menggunakan data yang dibaca dari buffer yang terdiri dari array byte. |
| WriteAsync(Byte[], Int32, Int32, CancellationToken) |
Secara asinkron menulis urutan byte ke aliran saat ini, memajukan posisi saat ini dalam aliran ini dengan jumlah byte yang ditulis, dan memantau permintaan pembatalan. (Diperoleh dari FileStream) |
| WriteAsync(Byte[], Int32, Int32) |
Secara asinkron menulis urutan byte ke aliran saat ini dan memajukan posisi saat ini dalam aliran ini dengan jumlah byte yang ditulis. (Diperoleh dari Stream) |
| WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) |
Secara asinkron menulis blok byte ke objek aliran file penyimpanan terisolasi menggunakan data yang dibaca dari buffer yang terdiri dari rentang memori byte baca-saja. |
| WriteByte(Byte) |
Menulis byte tunggal ke IsolatedStorageFileStream objek. |
Implementasi Antarmuka Eksplisit
| Nama | Deskripsi |
|---|---|
| IDisposable.Dispose() |
Merilis semua sumber daya yang Streamdigunakan oleh . (Diperoleh dari Stream) |
Metode Ekstensi
| Nama | Deskripsi |
|---|---|
| AsInputStream(Stream) |
Mengonversi aliran terkelola di aplikasi .NET untuk Windows Store ke aliran input di Windows Runtime. |
| AsOutputStream(Stream) |
Mengonversi aliran terkelola di aplikasi .NET untuk Windows Store ke aliran output di Windows Runtime. |
| AsRandomAccessStream(Stream) |
Mengonversi aliran yang ditentukan ke aliran akses acak. |
| ConfigureAwait(IAsyncDisposable, Boolean) |
Mengonfigurasi bagaimana menunggu tugas yang dikembalikan dari asinkron sekali pakai akan dilakukan. |
| CopyToAsync(Stream, PipeWriter, CancellationToken) |
Secara asinkron membaca byte dari Stream dan menulisnya ke yang ditentukan PipeWriter, menggunakan token pembatalan. |
| GetAccessControl(FileStream) |
Mengembalikan informasi keamanan file. |
| SetAccessControl(FileStream, FileSecurity) |
Mengubah atribut keamanan file yang ada. |