Differences between File, Directory, FileInfo, and DirectoryInfo

Source: Internet
Author: User

File and fileInfo:

The File class is a static class. Because all File methods are static, if you only want to perform one operation, the efficiency of using the File method is higher than that of using the corresponding FileInfo instance method. All File methods require the path of the File currently operated. The static method of the File class performs security checks on all methods. If you want to reuse an object multiple times, you can use the corresponding FileInfo instance method because security check is not always required.

File, directory, FileInfo, DirectoryInfo

File, directory can control multiple files so that each security check is performed, while FileInfo and DirectoryInfo can only control one file for only one security process.

Each time a static method operates on a file, the static method exists in the stack header. It is called by a class and then looks for the file to be operated. The process of searching for files to be operated is an IO process, which takes a long time. However, it does not need to traverse new objects in the heap area.

A common method is called by an object at that time. You need to create a new object (this process is not required for a static method). However, if the number of operations is large, the general method does not need to execute unnecessary and time-consuming IO operations again, so the overall speed can be increased!

Therefore, the number of execution methods determines which class is the best choice.

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.