Breaking News
yeni film izle hd film seyret film izle

Creating Objects In C#

Creating a DirectoryInfo or FileInfo object is very simple. The constructor takes the path to the file.
DirectoryInfo di = new DirectoryInfo(“C:\\Windows”);
FileInfo fi = new FileInfo(“C:\\Windows\\Notepad.exe”);
Listing All Files in a Directory
The following code snippet lists all the files in the “C:\Windows” directory.
DirectoryInfo di = new DirectoryInfo("C:\\Windows");
FileInfo[] fis = di.GetFiles();
foreach (FileInfo fi in fis)
Practical Example (FileHandling):
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace testFileHandling
    class Program
        static void Main(string[] args)
            // create a writer and open the file
            TextWriter tw = new StreamWriter
(@"C:\Documents and Settings\Administrator\Desktop\date.txt");

            // write a line of text to the file
            Console.WriteLine("Please enter your text---\n");
            string aa = Console.ReadLine();


            // close the stream
            // create reader & open file
            TextReader tr = new StreamReader
(@"C:\Documents and Settings\Administrator\Desktop\date.txt");

            // read a line of text
            Console.WriteLine("The file contain the text---\n");


            // close the stream
The Output is:
To Download File Handling example Click here.
To view downloaded examples, Please Ensure that .NET Framework is installed on your system.

Check Also

Errors in C#

There are three types of errors in C# that can be occur in your application. …