다음을 통해 공유


FileInfo.Length 속성

현재 파일의 크기를 가져옵니다.

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

구문

‘선언
Public ReadOnly Property Length As Long
‘사용 방법
Dim instance As FileInfo
Dim value As Long

value = instance.Length
public long Length { get; }
public:
property long long Length {
    long long get ();
}
/** @property */
public long get_Length ()
public function get Length () : long

속성 값

현재 파일의 크기입니다.

예외

예외 형식 조건

IOException

Refresh가 파일이나 디렉터리의 상태를 업데이트할 수 없는 경우

FileNotFoundException

파일이 없는 경우

- 또는 -

Length 속성이 디렉터리에 대해 호출되는 경우

설명

파일을 포함하는 파일 시스템이 이 정보를 지원하지 않으면 이 속성 값은 Null 참조(Visual Basic의 경우 Nothing)입니다.

다음 표에서는 일반적인 예 또는 관련된 I/O 작업의 예를 보여 줍니다.

수행 작업

참조 항목

텍스트 파일을 만듭니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에 씁니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에서 읽습니다.

방법: 파일의 텍스트 읽기

파일에 텍스트를 추가합니다.

방법: 로그 파일 열기 및 추가

File.AppendText

FileInfo.AppendText

파일을 복사합니다.

File.Copy

FileInfo.CopyTo

파일 이름을 바꾸거나 이동합니다.

File.Move

FileInfo.MoveTo

이진 파일에서 읽습니다.

방법: 새로 만든 데이터 파일 읽기 및 쓰기

이진 파일에 씁니다.

방법: 새로 만든 데이터 파일 읽기 및 쓰기

하위 디렉터리를 만듭니다.

CreateSubdirectory

디렉터리의 파일을 참조하십시오.

Name

디렉터리의 파일을 크기순으로 정렬합니다.

GetFileSystemInfos

파일 특성을 설정합니다.

SetAttributes

예제

다음 예제에서는 지정된 파일의 크기를 표시합니다.

' The following example displays the names and sizes
' of the files in the specified directory.
Imports System
Imports System.IO

Public Class FileLength

    Public Shared Sub Main()
        ' Make a reference to a directory.
        Dim di As New DirectoryInfo("c:\")
        ' Get a reference to each file in that directory.
        Dim fiArr As FileInfo() = di.GetFiles()
        ' Display the names and sizes of the files.
        Dim f As FileInfo
        Console.WriteLine("The directory {0} contains the following files:", di.Name)
        For Each f In fiArr
            Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length)
        Next f
    End Sub 'Main
End Class 'FileLength 
// The following example displays the names and sizes
// of the files in the specified directory.
using System;
using System.IO;

public class FileLength
{
    public static void Main()
    {
        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("c:\\");
        // Get a reference to each file in that directory.
        FileInfo[] fiArr = di.GetFiles();
        // Display the names and sizes of the files.
        Console.WriteLine("The directory {0} contains the following files:", di.Name);
        foreach (FileInfo f in fiArr)
            Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length);
    }
}
// The following example displays the names and sizes
// of the files in the specified directory.
using namespace System;
using namespace System::IO;
int main()
{
   
   // Make a reference to a directory.
   DirectoryInfo^ di = gcnew DirectoryInfo( "c:\\" );
   
   // Get a reference to each file in that directory.
   array<FileInfo^>^fiArr = di->GetFiles();
   
   // Display the names and sizes of the files.
   Console::WriteLine( "The directory {0} contains the following files:", di->Name );
   System::Collections::IEnumerator^ myEnum = fiArr->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      FileInfo^ f = safe_cast<FileInfo^>(myEnum->Current);
      Console::WriteLine( "The size of {0} is {1} bytes.", f->Name, f->Length );
   }
}
// The following example displays the names and sizes
// of the files in the specified directory.
import System.*;
import System.IO.*;

public class FileLength
{
    public static void main(String[] args)
    {
        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("c:\\");

        // Get a reference to each file in that directory.
        FileInfo fiArr[] = di.GetFiles();

        // Display the names and sizes of the files.
        Console.WriteLine("The directory {0} contains the following files:",
            di.get_Name());
        for (int iCtr = 0; iCtr < fiArr.length; iCtr++) {
            FileInfo f = fiArr[iCtr];
            Console.WriteLine("The size of {0} is {1} bytes.", f.get_Name(),
                System.Convert.ToString(f.get_Length()));
        }
    } //main
} //FileLength

플랫폼

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에서 지원

참고 항목

참조

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

기타 리소스

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