← Back to C# Course | Chapter 14: File I/O & Streams | Lesson 5 of 6

FileInfo क्या है

FileInfo किसी file के ID card जैसा है जो आपको उसका नाम, size, और dates बताता है, और आपको इसे copy या delete करने देता है। यह एक specific file describe करता है।

In this page:

  1. FileInfo
Syntax
csharp
FileInfo info = new FileInfo(path);
info.Name;
info.Length;
info.Exists;
info.LastWriteTime;

FileInfo

FileInfo एक specific file को represent करता है और Length, Exists, और LastWriteTime जैसी instance properties, साथ ही Delete() और CopyTo() जैसे methods उजागर करता है।

static File class के विपरीत, FileInfo बनने के बाद कुछ जानकारी cache करता है, जो एक ही file पर बार-बार checks के लिए ज़्यादा efficient हो सकता है। यह File के static methods का object-oriented counterpart है।

Note: FileInfo का उपयोग करें जब आपको एक ही file की कई properties inspect करनी हों — यह बार-बार filesystem calls से बचाता है जो File के static methods हर बार करते हैं।

उदाहरण: FileInfo

markup
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string path = "info.txt";
        File.WriteAllText(path, "some sample content");

        FileInfo info = new FileInfo(path);

        Console.WriteLine(info.Name);
        Console.WriteLine(info.Length);
        Console.WriteLine(info.Exists);
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. किसी ऐसी file के लिए info.Length पढ़ना जो मौजूद नहीं, जो एक FileNotFoundException फेंकता है; पहले info.Exists जांचें।
  2. file बदलने के बाद एक FileInfo reuse करना और stale values पढ़ना, क्योंकि properties info.Refresh() call करने तक cached रहती हैं।
  3. Length को characters की संख्या मानना, जबकि यह bytes में file size है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.