开发者

What is the difference between System.IO.File and System.IO.FileInfo

Why there are two class for the 开发者_C百科almost same purpose System.IO.File and System.IO.FileInfo.


System.IO.File provides static members related to working with files, whereas System.IO.FileInfo represents a specific file and contains non-static members for working with that file.

From MSDN:

Because all File methods are static, it might be more efficient to use a File method rather than a corresponding FileInfo instance method if you want to perform only one action. All File methods require the path to the file that you are manipulating.

The static methods of the File class perform security checks on all methods. If you are going to reuse an object several times, consider using the corresponding instance method of FileInfo instead, because the security check will not always be necessary.


In general they do two very different things:

  • System.IO.File - getting/working with any file
  • System.IO.FileInto - getting/working with (including metadata) a particular file

Granted they do share a few methods with the same purpose, but for the most part they have very different purposes/scenarios that they serve best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜