C # uses the FileInfo class to create and delete files

Source: Internet
Author: User
Through the FileInfo class, we can easily create files, and can access the properties of the file can also open files, close files, read and write files and other basic operations. The following code shows how to create a text file and Access file information such as its creation time, the absolute path of the file, and the file properties, and finally the method of deleting the file.

FileInfo fi = new FileInfo (@ "F:\Myprogram.txt");
FileStream fs = fi. Create ();
Console.WriteLine ("Creation time: {0}", fi. CreationTime);
Console.WriteLine ("Full Name: {0}", fi. FullName);
Console.WriteLine ("FileAttributes: {0}", fi. Attributes.tostring ());
Console.WriteLine ("Press any key to delete the file");
Console.read ();
Fstr. Close ();
Fi. Delete ();

C # uses the FileInfo class to create and delete files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.