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
특성

필드

Name Description
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는 , , SeekStream, BufferedStreamFileStream및 기타 클래스의 MemoryStream메서드에서 사용됩니다BinaryWriter. 메서드는 Seek 에 지정된 SeekOrigin위치를 기준으로 하는 오프셋 매개 변수를 사용합니다.

적용 대상

추가 정보