문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
java:7:files [2011/09/14 22:10] kwon37xi |
java:7:files [2022/04/05 23:59] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 4: | 줄 4: | ||
| [[http:// | [[http:// | ||
| + | * [[http:// | ||
| ===== Path ===== | ===== Path ===== | ||
| 파일의 경로는 [[http:// | 파일의 경로는 [[http:// | ||
| 줄 17: | 줄 18: | ||
| Path path = Paths.get(" | Path path = Paths.get(" | ||
| //혹은 FileSystem 객체로 부터... | //혹은 FileSystem 객체로 부터... | ||
| - | // Path pathFromFS = FileSystems.getDefault().getPath(" | + | Path pathFromFS = FileSystems.getDefault().getPath(" |
| System.out.println(" | System.out.println(" | ||
| </ | </ | ||
| + | |||
| + | ===== Files ===== | ||
| + | [[http:// | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | ===== Directory 삭제 ===== | ||
| + | * [[https:// | ||
| + | <code java> | ||
| + | public void whenDeletedWithNIO2WalkFileTree_thenIsGone() | ||
| + | throws IOException { | ||
| + | |||
| + | Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); | ||
| + | |||
| + | Files.walkFileTree(pathToBeDeleted, | ||
| + | new SimpleFileVisitor< | ||
| + | @Override | ||
| + | public FileVisitResult postVisitDirectory( | ||
| + | Path dir, IOException exc) throws IOException { | ||
| + | Files.delete(dir); | ||
| + | return FileVisitResult.CONTINUE; | ||
| + | } | ||
| + | | ||
| + | @Override | ||
| + | public FileVisitResult visitFile( | ||
| + | Path file, BasicFileAttributes attrs) | ||
| + | throws IOException { | ||
| + | Files.delete(file); | ||
| + | return FileVisitResult.CONTINUE; | ||
| + | } | ||
| + | }); | ||
| + | |||
| + | assertFalse(" | ||
| + | Files.exists(pathToBeDeleted)); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||