다음 파일을 찾아야 한다고 가정해 봅시다 -
E:\new.txt
위 파일의 존재를 확인하려면 Exists() 메소드를 사용하십시오 -
if (File.Exists(@"E:\new.txt")) {
Console.WriteLine("File exists...");
} 다음은 파일의 존재를 확인하는 완전한 코드입니다 -
예시
using System;
using System.IO;
public class Demo {
public static void Main() {
if (File.Exists(@"E:\new.txt")) {
Console.WriteLine("File exists...");
} else {
Console.WriteLine("File does not exist in the E directory!");
}
}
} 출력
File does not exist in the E directory!