먼저 전체 코드를 살펴 보겠습니다.
import java.io.file; public class judgefile {public static void main (String [] args) {file dir = new File ( "d :/"); // d 디스크 파일을 선언합니다. 파일 = 새 파일 (dir, "test"); // boolean d = dir.exists (); boolean f = file.exists (); if (d == true) {system.out.println (dir.getAbsolutepath ()+"directory"); ESTER ");} if (f == true) {system.out.println (file.getAbsolutepath ()+"파일이 존재하지 않는다 ");} else {system.out.println (file.getAbsolutePath ()+"파일이 존재하지 않는다 ");}}}}설명 :
파일 또는 디렉토리가 존재하는지 여부를 감지하기 위해 () 메소드가 있습니다.
getAbsolutepath () 메소드는 디스크 경로를 인쇄합니다
디렉토리가 선언되지 않은 경우, 예를 들어 파일 = 새 파일 ( "테스트"); 기본 경로는 Java 프로젝트 폴더의 경로입니다.