I\'ve been reading that the static methods of the File
Class are better used to perform small and few tasks on a file like checking to see if it exists and that
FileInfo is an instance of a file thus representing the file itself. File is a utility class so can work with any file
File is optimized for one-off operations on a file, FileInfo is optimized around multiple operations on the same file, but in general there isn't that much difference between the different method implementations.
If you want to compare the exact implementations, Use Reflector to look at both classes.
FileInfo:
File:
src:
Recently I faced problem with File.Exist
, I hate this function. After than I've used Fileinfo
class Exist
function then my program works correct.
Actually what happen in development enviornment File.Exist
works well but when it goes to live environment this function is blocking the file object due to that reason I am getting the error access denied and not able to use the file.
This is my learning.
I will never used File.Exist
method best is to create the object and then use it. Be aware to use static methods.