Framework/Springboot [Springboot] 스프링부트 파일 클래스(File Class) - 728x90 반응형 ▶ File 클래스 - java.io 패키지에서 제공 - 파일 및 폴더 정보 제공 File file = new File("C:/Temp/file.txt"); File file = new File("C:\\Temp\\file.txt"); - 파일이나 폴더가 존재하는지 확인하려면 exists() 메소드 호출 boolean isExist = file.exists(); - exists() 메소드의 반환값이 false 인 경우 다음 메소드로 파일 또는 폴더 생성 - exists() 메소드의 반환값이 true 인 경우 다음 메소드로 파일 또는 폴더 생성 File dir = new File("text"); if(!dir.exists()) {dir.mkdirs();} File file1 = new File("text/file1.txt"); if(!file1.exists()) file1.createNewFile(); File file2 = new File("text/file2.txt"); if(!file2.exists()) file2.createNewFile(); File file3 = new File("text/file3.txt"); if(!file3.exists()) file3.createNewFile(); File text = new File("text"); File[] files = text.listFiles(); for(File f : files) { System.out.println(f.getName()); System.out.println(f.getPath()); } 728x90 반응형 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기Feat Dev Contents 추천 컨텐츠 [Springboot] 스프링부트 예외처리 (try~catch~finally) 2023.11.13 [Springboot] 스프링부트 데이터 수집 2023.11.13 [Springboot] 스프링부트 입출력 스트림 2023.11.13 [Springboot] 스프링부트 H2 연동 2023.11.13 -