티스토리 뷰
java.io.File
메서드 | 설명 |
---|---|
boolean canRead() | 읽을 수 있는 파일인지 검사한다. |
boolean canWrite() | 쓸 수 있는 파일인지 검사한다 |
boolean canExecute() | 실행할 수 있는 파일인지 검사한다 |
int compareTo(File pathName) | 지정한 파일(pathname)과 비교한다 |
boolean exist() | 파일이 존재하는지 검사한다. |
boolean isAbsolute() | 파일 또는 디렉토리가 절대경로명으로 지정되었는지 확인한다 |
boolean isDirectory() | 디렉토리인지 확인한다 |
boolean isFile() | 파일인지 확인한다. |
boolean createNewFile() | 아무런 내용이 없는 새로운 파일을 생성한다. (단, 이미 생성하려는 파일이 이미 존재하면 생성되지 않는다.) |
static File createTempFile(String prefix, String suffix) | 임시파일을 시스템의 지정된 디렉토리에 생성한다 |
boolean delete() | 파일을 삭제한다 |
void deleteOnExit | 응용 프로그램 종료시 파일을 삭제한다 |
boolean equals(Object obj) | 주어진 객체가 같은 파일인지 비교한다 |
long length() | 파일의 크기를 반환한다 |
String[] list() | 디렉토리의 파일목록(디렉토리 포함)을 String 배열로 반환한다. |
String[] list(FilenameFilter filter) | FileNameFilter 인스턴스에 구현된 조건에 맞는 파일을 String 배열로 반환한다. |
File[] listFiles() | 디렉토리의 파일목록(디렉토리 포함)을 File배열로 반환한다. |
File[] listFiles(FilenameFilter filter) | 디렉토리의 파일목록(디렉토리 포함)에서 Filter의 조건과 일치하는 파일들을 File 배열로 반환한다. |
Path toPath() | 파일을 Path로 변환해서 반환한다 |
URI toURI() | 파일을 URI로 반환해서 반환한다 |
java-practice
ㄴsrc
ㄴtest
ㄴfile
ㄴFileExample.java
ㄴfacebook.png
public class FileExample {
public static void main(String[] args) throws Exception {
File f = new File("C:\\Spring\\java-practice\\src\\facebook.png");
System.out.println("canRead : " + f.canRead());
System.out.println("canWrite : " + f.canWrite());
System.out.println("canExecute : " + f.canExecute());
System.out.println("isAbsolute : " + f.isAbsolute());
System.out.println("getPath : " + f.getPath());
System.out.println("lengh : " + f.length());
System.out.println("file exist? : " + f.exists());
System.out.println("directory? : "+ f.isDirectory());
}
}
canRead : true
canWrite : true
canExecute : true
isAbsolute : true
getPath : C:\Spring\java-practice\src\facebook.png
lengh : 977
file exist? : true
directory? : false
참고자료
'Java > 기초' 카테고리의 다른 글
[java] 스트림(Stream) 기초 (0) | 2021.12.22 |
---|---|
[java] FileNameFilter로 특정 파일만 찾기 (0) | 2020.12.06 |
[java] File : getPath(), getAbsolutePath(), geCanonicalPath() 차이 (0) | 2020.12.06 |
[java] Optional 기초 : NPE에서 벗어나보자 (0) | 2020.08.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- mysql 온라인 ddl
- jpa 쿼리 로그
- spring retry
- 이모지입력오류
- github actions components
- file
- csv 라이브러리
- http커넥션
- 엔티티와값객체
- TCP연결
- 콜레이션변경
- mysql 이모지
- 쿼리 파라미터 바인딩
- online ddl
- tcp커넥션
- 콜레이션
- CGLIB프록시
- read timeout
- utf8mb3
- opencsv
- 코프링
- AOP
- 4Way Handshake
- hibernate 쿼리 로그
- csv to bean
- 문자집합변경
- github actions 구성요소
- spring boot3 쿼리 로그
- 도메인구성요소
- github actions 기초
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함