FileStream.Name 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得在 FileStream
中開啟之檔案的絕對路徑。
public:
property System::String ^ Name { System::String ^ get(); };
public:
virtual property System::String ^ Name { System::String ^ get(); };
public string Name { get; }
public virtual string Name { get; }
member this.Name : string
Public ReadOnly Property Name As String
Public Overridable ReadOnly Property Name As String
屬性值
字串,這是檔案的絕對路徑。
範例
此程式代碼範例是為建構函式提供的較大範例的 FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) 一部分。
static void EndReadCallback( IAsyncResult^ asyncResult )
{
State^ tempState = dynamic_cast<State^>(asyncResult->AsyncState);
int readCount = tempState->FStream->EndRead( asyncResult );
int i = 0;
while ( i < readCount )
{
if ( tempState->ReadArray[ i ] != tempState->WriteArray[ i++ ] )
{
Console::WriteLine( "Error writing data." );
tempState->FStream->Close();
return;
}
}
Console::WriteLine( "The data was written to {0} "
"and verified.", tempState->FStream->Name );
tempState->FStream->Close();
// Signal the main thread that the verification is finished.
tempState->ManualEvent->Set();
}
public:
static void EndReadCallback(IAsyncResult asyncResult)
{
State tempState = (State)asyncResult.AsyncState;
int readCount = tempState.FStream.EndRead(asyncResult);
int i = 0;
while(i < readCount)
{
if(tempState.ReadArray[i] != tempState.WriteArray[i++])
{
Console.WriteLine("Error writing data.");
tempState.FStream.Close();
return;
}
}
Console.WriteLine("The data was written to {0} and verified.",
tempState.FStream.Name);
tempState.FStream.Close();
// Signal the main thread that the verification is finished.
tempState.ManualEvent.Set();
}
let endReadCallback (asyncResult: IAsyncResult) =
let tempState = asyncResult.AsyncState :?> State
let readCount = tempState.FStream.EndRead asyncResult
let mutable i = 0
let mutable errored = false
while i < readCount do
if tempState.ReadArray[i] <> tempState.WriteArray[i] then
printfn "Error writing data."
tempState.FStream.Close()
errored <- true
i <- readCount
i <- i + 1
printfn $"The data was written to {tempState.FStream.Name} and verified."
tempState.FStream.Close()
// Signal the main thread that the verification is finished.
tempState.ManualEvent.Set() |> ignore
Private Shared Sub EndReadCallback(asyncResult As IAsyncResult)
Dim tempState As State = _
DirectCast(asyncResult.AsyncState, State)
Dim readCount As Integer = _
tempState.FStream.EndRead(asyncResult)
Dim i As Integer = 0
While(i < readCount)
If(tempState.ReadArray(i) <> tempState.WriteArray(i))
Console.WriteLine("Error writing data.")
tempState.FStream.Close()
Return
End If
i += 1
End While
Console.WriteLine("The data was written to {0} and " & _
"verified.", tempState.FStream.Name)
tempState.FStream.Close()
' Signal the main thread that the verification is finished.
tempState.ManualEvent.Set()
End Sub
備註
如果不知道絕對路徑,這個屬性會傳回類似 “[Unknown]” 的字串。
如需一般檔案和目錄作業的清單,請參閱 一般 I/O 工作。