You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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.