programming-examples/c-sharp/Files/C# Program to Illustrate Methods of FileInfo Class.cs
2019-11-15 12:59:38 +01:00

49 lines
1.4 KiB
C#

/*
* C# Program to Illustrate Methods of FileInfo Class
*/
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = Path.GetTempFileName();
FileInfo fi1 = new FileInfo(path);
using (StreamWriter sw = fi1.CreateText())
{
sw.WriteLine("This is");
sw.WriteLine("Codenza");
sw.WriteLine("Website");
}
using (StreamReader sr = fi1.OpenText())
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
try
{
string path2 = Path.GetTempFileName();
FileInfo fi2 = new FileInfo(path2);
fi2.Delete();
fi1.CopyTo(path2);
Console.WriteLine("{0} was copied to {1}.", path, path2);
fi2.Delete();
Console.WriteLine("{0} was successfully deleted.", path2);
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
Console.Read();
}
}
/*
This is
Codenza
Website.
C:\Users\win7\AppData\Local\Temp\tmpAEF8.tmp was copied to C:\users\Win7\AppData\Local\Temp\tmpAEF7.tmp
C:\users\Win7\AppData\Local\Temp\tmpAEF8.tmp was successfully deleted.