FileSystemProxy.OpenTextFieldParser 메서드

정의

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

오버로드

OpenTextFieldParser(String, Int32[])

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

OpenTextFieldParser(String, String[])

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

OpenTextFieldParser(String)

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

OpenTextFieldParser(String, Int32[])

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

public:
 Microsoft::VisualBasic::FileIO::TextFieldParser ^ OpenTextFieldParser(System::String ^ file, ... cli::array <int> ^ fieldWidths);
public Microsoft.VisualBasic.FileIO.TextFieldParser OpenTextFieldParser (string file, params int[] fieldWidths);
member this.OpenTextFieldParser : string * int[] -> Microsoft.VisualBasic.FileIO.TextFieldParser
Public Function OpenTextFieldParser (file As String, ParamArray fieldWidths As Integer()) As TextFieldParser

매개 변수

file
String

TextFieldParser로 열 파일입니다.

fieldWidths
Int32[]

필드의 너비입니다.

반환

지정된 파일을 읽을 TextFieldParser입니다.

예외

경로는 길이가 0인 문자열인 다음 이유 중 하나로 유효하지 않습니다. 공백만 포함됩니다. 잘못된 문자가 포함되어 있습니다. 또는 디바이스 경로(\\.\로 시작)입니다. 후행 슬래시로 끝납니다.

file이(가) Nothing인 경우

파일이 없습니다.

다른 프로세스에서 파일을 사용 중이거나 I/O 오류가 발생한 경우

경로가 시스템 정의 최대 길이를 초과하는 경우

경로의 파일 이름이나 디렉터리 이름에 콜론(:)이 있거나 이름의 형식이 잘못된 경우

지정된 형식을 사용하여 행을 구문 분석할 수 없는 경우 예외 메시지에는 예외를 발생시키는 줄이 지정되어 있지만 ErrorLine 속성은 해당 줄에 포함되어 있는 텍스트에 할당됩니다.

경로를 보는 데 필요한 권한이 사용자에게 없는 경우

예제

이 예제에서는 TextFieldParser.reader를 열고 이를 사용하여 C:\TestFolder1\Test1.txt에서 읽습니다.

Dim reader = My.Computer.FileSystem.OpenTextFieldParser(
    "C:\TestFolder1\test1.txt")
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.delimiters = {","}
Dim currentRow As String()
While Not reader.EndOfData
    Try
        currentRow = reader.ReadFields()
        Dim currentField As String
        For Each currentField In currentRow
            MsgBox(currentField)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & ex.Message &
        "is not valid and will be skipped.")
    End Try
End While

설명

다음 표에서 관련 된 작업의 예제는 My.Computer.FileSystem.OpenTextFieldParser 메서드.

대상 참조 항목
구분된 텍스트 파일에서 읽기 방법: 쉼표로 구분된 텍스트 파일에서 읽기
고정 너비 텍스트 파일에서 읽기 방법: 고정 너비 텍스트 파일에서 읽기
여러 형식의 텍스트 파일에서 읽기 방법: 여러 형식의 텍스트 파일에서 읽기

추가 정보

적용 대상

OpenTextFieldParser(String, String[])

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

public:
 Microsoft::VisualBasic::FileIO::TextFieldParser ^ OpenTextFieldParser(System::String ^ file, ... cli::array <System::String ^> ^ delimiters);
public Microsoft.VisualBasic.FileIO.TextFieldParser OpenTextFieldParser (string file, params string[] delimiters);
member this.OpenTextFieldParser : string * string[] -> Microsoft.VisualBasic.FileIO.TextFieldParser
Public Function OpenTextFieldParser (file As String, ParamArray delimiters As String()) As TextFieldParser

매개 변수

file
String

TextFieldParser로 열 파일입니다.

delimiters
String[]

필드에 사용하는 구분 기호입니다.

반환

지정된 파일을 읽을 TextFieldParser입니다.

예외

경로는 길이가 0인 문자열인 다음 이유 중 하나로 유효하지 않습니다. 공백만 포함됩니다. 잘못된 문자가 포함되어 있습니다. 또는 디바이스 경로(\\.\로 시작)입니다. 후행 슬래시로 끝납니다.

file이(가) Nothing인 경우

파일이 없습니다.

다른 프로세스에서 파일을 사용 중이거나 I/O 오류가 발생한 경우

경로가 시스템 정의 최대 길이를 초과하는 경우

경로의 파일 이름이나 디렉터리 이름에 콜론(:)이 있거나 이름의 형식이 잘못된 경우

지정된 형식을 사용하여 행을 구문 분석할 수 없는 경우 예외 메시지에는 예외를 발생시키는 줄이 지정되어 있지만 ErrorLine 속성은 해당 줄에 포함되어 있는 텍스트에 할당됩니다.

경로를 보는 데 필요한 권한이 사용자에게 없는 경우

예제

이 예제에서는 TextFieldParser.reader를 열고 이를 사용하여 C:\TestFolder1\Test1.txt에서 읽습니다.

Dim reader = My.Computer.FileSystem.OpenTextFieldParser(
    "C:\TestFolder1\test1.txt")
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.delimiters = {","}
Dim currentRow As String()
While Not reader.EndOfData
    Try
        currentRow = reader.ReadFields()
        Dim currentField As String
        For Each currentField In currentRow
            MsgBox(currentField)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & ex.Message &
        "is not valid and will be skipped.")
    End Try
End While

설명

다음 표에서 관련 된 작업의 예제는 My.Computer.FileSystem.OpenTextFieldParser 메서드.

대상 참조 항목
구분된 텍스트 파일에서 읽기 방법: 쉼표로 구분된 텍스트 파일에서 읽기
고정 너비 텍스트 파일에서 읽기 방법: 고정 너비 텍스트 파일에서 읽기
여러 형식의 텍스트 파일에서 읽기 방법: 여러 형식의 텍스트 파일에서 읽기

추가 정보

적용 대상

OpenTextFieldParser(String)

OpenTextFieldParser 메서드를 사용하면 로그와 같은 구조적 텍스트 파일을 쉽고 효과적으로 구문 분석하는 방법을 제공하는 TextFieldParser 개체를 만들 수 있습니다. TextFieldParser 개체는 구분된 파일과 고정 너비 파일을 모두 읽는 데 사용될 수 있습니다.

public:
 Microsoft::VisualBasic::FileIO::TextFieldParser ^ OpenTextFieldParser(System::String ^ file);
public Microsoft.VisualBasic.FileIO.TextFieldParser OpenTextFieldParser (string file);
member this.OpenTextFieldParser : string -> Microsoft.VisualBasic.FileIO.TextFieldParser
Public Function OpenTextFieldParser (file As String) As TextFieldParser

매개 변수

file
String

TextFieldParser로 열 파일입니다.

반환

지정된 파일을 읽을 TextFieldParser입니다.

예외

경로는 길이가 0인 문자열인 다음 이유 중 하나로 유효하지 않습니다. 공백만 포함됩니다. 잘못된 문자가 포함되어 있습니다. 또는 디바이스 경로(\\.\로 시작)입니다. 후행 슬래시로 끝납니다.

file이(가) Nothing인 경우

파일이 없습니다.

다른 프로세스에서 파일을 사용 중이거나 I/O 오류가 발생한 경우

경로가 시스템 정의 최대 길이를 초과하는 경우

경로의 파일 이름이나 디렉터리 이름에 콜론(:)이 있거나 이름의 형식이 잘못된 경우

지정된 형식을 사용하여 행을 구문 분석할 수 없는 경우 예외 메시지에는 예외를 발생시키는 줄이 지정되어 있지만 ErrorLine 속성은 해당 줄에 포함되어 있는 텍스트에 할당됩니다.

경로를 보는 데 필요한 권한이 사용자에게 없는 경우

예제

이 예제에서는 TextFieldParser.reader를 열고 이를 사용하여 C:\TestFolder1\Test1.txt에서 읽습니다.

Dim reader = My.Computer.FileSystem.OpenTextFieldParser(
    "C:\TestFolder1\test1.txt")
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.delimiters = {","}
Dim currentRow As String()
While Not reader.EndOfData
    Try
        currentRow = reader.ReadFields()
        Dim currentField As String
        For Each currentField In currentRow
            MsgBox(currentField)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & ex.Message &
        "is not valid and will be skipped.")
    End Try
End While

설명

다음 표에서 관련 된 작업의 예제는 My.Computer.FileSystem.OpenTextFieldParser 메서드.

대상 참조 항목
구분된 텍스트 파일에서 읽기 방법: 쉼표로 구분된 텍스트 파일에서 읽기
고정 너비 텍스트 파일에서 읽기 방법: 고정 너비 텍스트 파일에서 읽기
여러 형식의 텍스트 파일에서 읽기 방법: 여러 형식의 텍스트 파일에서 읽기

추가 정보

적용 대상