다음을 통해 공유


FileStream.CanSeek 속성

현재 스트림이 검색을 지원하는지 여부를 나타내는 값을 가져옵니다.

네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Overrides ReadOnly Property CanSeek As Boolean
‘사용 방법
Dim instance As FileStream
Dim value As Boolean

value = instance.CanSeek
public override bool CanSeek { get; }
public:
virtual property bool CanSeek {
    bool get () override;
}
/** @property */
public boolean get_CanSeek ()
public override function get CanSeek () : boolean

속성 값

현재 스트림이 검색을 지원하면 true이고, 스트림이 닫혔거나 FileStream이 콘솔에 대한 출력 또는 파이프와 같은 운영 체제 핸들로부터 생성된 경우에는 false입니다.

설명

Stream에서 파생된 클래스가 검색을 지원하지 않는 경우 Length, SetLength, PositionSeek 메서드를 호출하면 NotSupportedException이 throw됩니다.

스트림이 닫혀 있으면 이 속성은 false를 반환합니다.

예제

다음 예제에서는 CanSeek 속성을 사용하여 스트림이 검색을 지원하는지 여부를 확인합니다.

Imports System
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
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);
            }
        }
    }
}
using namespace System;
using namespace System::IO;
using namespace System::Text;

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
   {
      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 );
      }
   }
   finally
   {
      if ( fs )
         delete (IDisposable^)fs;
   }
}
import System.*;
import System.IO.*;
import System.Text.*;

class Test
{
    public static void main(String[] args)
    {
        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 {
            if (fs.get_CanSeek()) {
                Console.WriteLine("The stream connected to {0} " 
                    + "is seekable.", path);
            }
            else {
                Console.WriteLine("The stream connected to {0} is not " 
                    + " seekable.", path);
            }
        }
        finally {
            fs.Dispose();
        }

    } //main
} //Test

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

FileStream 클래스
FileStream 멤버
System.IO 네임스페이스

기타 리소스

파일 및 스트림 I/O
방법: 파일의 텍스트 읽기
방법: 파일에 텍스트 쓰기