다음을 통해 공유


방법: Visual Basic에서 파일 만들기

다음은 클래스의 메서드 Create 를 사용하여 File 지정된 경로에 빈 텍스트 파일을 만드는 예제입니다.

예시

Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"

        ' Create or overwrite the file.
        Dim fs As FileStream = File.Create(path)

        ' Add text to the file.
        Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")
        fs.Write(info, 0, info.Length)
        fs.Close()
    End Sub

End Module

코드 컴파일

변수를 file 사용하여 파일에 씁니다.

강력한 프로그래밍

파일이 이미 있는 경우 바뀝니다.

다음 조건에서 예외가 발생합니다.

.NET Framework 보안

부분 신뢰 환경에서 SecurityException가 던져질 수 있습니다.

Create 메서드를 호출하려면 FileIOPermission가 필요합니다.

파일을 생성할 수 있는 권한이 사용자에게 없으면 UnauthorizedAccessException 예외가 발생됩니다.

참고하십시오