Why there are two class for the almost same purpose System.IO.File and System.IO.FileInfo.
-
2I wish you could downvote comments. – Rei Miyasaka Oct 23 '10 at 09:14
-
2@Rei Miyasaka: and why is that? – Mitch Wheat Oct 23 '10 at 09:18
-
1Because you're being neither helpful nor friendly nor funny. – Rei Miyasaka Oct 23 '10 at 09:43
-
Possible duplicate? https://stackoverflow.com/questions/1324788/what-is-the-difference-between-file-and-fileinfo-in-c – andreyk2 Hohlov Jan 09 '21 at 16:41
2 Answers
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.

- 175,602
- 35
- 392
- 393
In general they do two very different things:
System.IO.File
- getting/working with any fileSystem.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.

- 623,446
- 136
- 1,297
- 1,155