docs.microsoft.com/ko-kr/dotnet/api/system.io.fileinfo?view=net-5.0

 

FileInfo Class (System.IO)

Provides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited.

docs.microsoft.com

FileFileInfo는 각각 System.IO에서 지원해준다.

두가지의 가장 큰 차이점은 Filestatic 매서드 이고 FileInfoinstance 매서드이다.

 

상황에 맞춰서 쓰면 되고 두개의 기능은 비슷하지만 지원해주는 프로퍼티나 매서드가 차이가있다.

 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace io_1
{
class Program
{
static void Main(string[] args)
{
var path = @"c:\somefile.jpg";
// Copy
File.Copy(path, @"d:\temp\myfile.jpg", true);
// Delete
File.Delete(path);
// Exists
if (File.Exists(path))
{
Console.WriteLine(File.ReadAllText(path));
}
else
{
Console.WriteLine("No File !");
}
// Read
var content = File.ReadAllText(path);
var fileInfo = new FileInfo(path);
// Copy
fileInfo.CopyTo("...");
// Delete
fileInfo.Delete();
// Exists
if (fileInfo.Exists)
{
Console.WriteLine(fileInfo.OpenRead());
}
else
{
Console.WriteLine("No File !");
}
}
}
}

'C# > Basic' 카테고리의 다른 글

Path  (0) 2021.03.10
Directory, DirectoryInfo  (0) 2021.03.09
제네릭 (Generic) 1  (0) 2021.02.28
상속 (inheritance)  (0) 2021.02.25
접근 제한자 (Access Modifier)  (0) 2021.02.14