-
[NIO.2]Checking a File or DirectoryJAVA/NIO2 2013. 11. 25. 14:57728x90
파일 또는 디렉토리 확인
1. 존재 여부 확인
- exists(Path, LinkOption...) : 존재 할 경우 true
- notExists(Path, LinkOption...) : 존재 하지 않을 경우 true
만약 exists와 notExists의 결과가 동일하게 false 일 경우 Path의 값이 명확하지 않을 경우다.
2. 파일 권한
- isReadable(Path) : 읽기 가능할 경우 true
- isWritable(Path) : 쓰기 가능할 경우 true
- isExecutable(Path) : 실행 가능할 경우 true
Path file = ...; boolean isRegularExecutableFile = Files.isRegularFile(file) & Files.isReadable(file) & Files.isExecutable(file);
3. 같은 파일인지 확인
- isSameFile(Path, Path)
Path p1 = ...; Path p2 = ...; if (Files.isSameFile(p1, p2)) { // Logic when the paths locate the same file }
참조 : http://docs.oracle.com/javase/tutorial/essential/io/check.html
728x90'JAVA > NIO2' 카테고리의 다른 글
[NIO.2]Copying a File or Directory (0) 2013.11.25 [NIO.2]Deleting a File or Directory (0) 2013.11.25 [NIO.2]Files Class (0) 2013.11.20 [NIO.2]The Path Class (0) 2013.11.13 [JAVA.7]NIO2 노트 시작 합니다. (0) 2013.11.12