SeekOrigin 열거형

정의

탐색에 사용할 스트림 내 위치를 지정합니다.

public enum class SeekOrigin
public enum SeekOrigin
[System.Serializable]
public enum SeekOrigin
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum SeekOrigin
type SeekOrigin = 
[<System.Serializable>]
type SeekOrigin = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SeekOrigin = 
Public Enum SeekOrigin
상속
SeekOrigin
특성

필드

Begin 0

스트림의 맨 앞을 지정합니다.

Current 1

스트림 내의 현재 위치를 지정합니다.

End 2

스트림의 맨 끝을 지정합니다.

예제

다음 예에서는 스트림의 끝 이전 버전과 시작을 읽는 방법 및 스트림에 지정된 된 지점에서 읽는 방법을 보여 줍니다.

using System;
using System.IO;

public class FSSeek
{
    public static void Main()
    {
        long offset;
        int nextByte;

        // alphabet.txt contains "abcdefghijklmnopqrstuvwxyz"
        using (FileStream fs = new FileStream(@"c:\temp\alphabet.txt", FileMode.Open, FileAccess.Read))
        {
            for (offset = 1; offset <= fs.Length; offset++)
            {
                fs.Seek(-offset, SeekOrigin.End);
                Console.Write((char)fs.ReadByte());
            }
            Console.WriteLine();

            fs.Seek(20, SeekOrigin.Begin);

            while ((nextByte = fs.ReadByte()) > 0)
            {
                Console.Write((char)nextByte);
            }
            Console.WriteLine();
        }
    }
}
// This code example displays the following output:
//
// zyxwvutsrqponmlkjihgfedcba
// uvwxyz
Imports System.IO

Public Class FSSeek
    Public Shared Sub Main()
        Dim offset As Long
        Dim nextByte As Integer

        ' alphabet.txt contains "abcdefghijklmnopqrstuvwxyz"
        Using fs As New FileStream("c:\temp\alphabet.txt", FileMode.Open, FileAccess.Read)

            For offset = 1 To fs.Length
                fs.Seek(-offset, SeekOrigin.End)
                Console.Write(Convert.ToChar(fs.ReadByte()))
            Next offset
            Console.WriteLine()

            fs.Seek(20, SeekOrigin.Begin)

            nextByte = fs.ReadByte()
            While (nextByte > 0)
                Console.Write(Convert.ToChar(nextByte))
                nextByte = fs.ReadByte()
            End While
            Console.WriteLine()

        End Using
    End Sub
End Class

' This code example displays the following output:
'
' zyxwvutsrqponmlkjihgfedcba
' uvwxyz

설명

SeekOrigin 사용 되는 Seek 의 메서드 Stream, BufferedStream, FileStreamMemoryStream, BinaryWriter, 및 기타 클래스입니다. 합니다 Seek 메서드는 지정 된 위치를 기준으로 하는 오프셋된 매개 변수 사용 SeekOrigin합니다.

적용 대상

추가 정보