FileStream.CanSeek 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 스트림에서 검색을 지원하는지 여부를 나타내는 값을 가져옵니다.
public:
virtual property bool CanSeek { bool get(); };
public override bool CanSeek { get; }
member this.CanSeek : bool
Public Overrides ReadOnly Property CanSeek As Boolean
속성 값
true 스트림이 검색을 지원하는 경우 false 스트림이 닫혀 있거나 파이프 또는 출력과 같은 운영 체제 핸들에서 콘솔로 생성된 경우 FileStream 입니다.
예제
다음 예제에서는 속성을 사용하여 스트림이 CanSeek 검색을 지원하는지 여부를 확인합니다.
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))
{
if (fs.CanSeek)
{
Console.WriteLine("The stream connected to {0} is seekable.", path);
}
else
{
Console.WriteLine("The stream connected to {0} is not seekable.", path);
}
}
}
}
open System.IO
let path = @"c:\temp\MyTest.txt"
// Delete the file if it exists.
if File.Exists path then
File.Delete path
//Create the file.
do
use fs = File.Create path
if fs.CanSeek then
printfn $"The stream connected to {path} is seekable."
else
printfn $"The stream connected to {path} is not seekable."
Imports System.IO
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)
If fs.CanSeek Then
Console.WriteLine("The stream connected to {0} is seekable.", path)
Else
Console.WriteLine("The stream connected to {0} is not seekable.", path)
End If
fs.Close()
End Sub
End Class
설명
파생된 Stream 클래스가 검색을 지원하지 않는 경우 , , SetLengthPosition및 Seek throw를 Length호출합니다NotSupportedException.
스트림이 닫혀 있으면 이 속성이 반환됩니다 false.