사용자 도구

사이트 도구


java:7:files

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:7:files [2011/09/14 22:11]
kwon37xi
java:7:files [2022/04/05 23:59] (현재)
kwon37xi
줄 4: 줄 4:
 [[http://download.oracle.com/javase/tutorial/essential/io/fileio.html|File I/O (Featuring NIO.2) (The Java™ Tutorials > Essential Classes > Basic I/O)]] 에서 자세히 볼 수 있으며 아래는 간단한 정리이다.. [[http://download.oracle.com/javase/tutorial/essential/io/fileio.html|File I/O (Featuring NIO.2) (The Java™ Tutorials > Essential Classes > Basic I/O)]] 에서 자세히 볼 수 있으며 아래는 간단한 정리이다..
  
 +  * [[http://www.javabeat.net/2012/06/creating-writing-reading-java-files-api-java-7/|Creating, Writing, Reading files using Java Files API of Java 7]]
 ===== Path ===== ===== Path =====
 파일의 경로는 [[http://download.oracle.com/javase/7/docs/api/java/nio/file/Path.html|java.nio.file.Path]] 인터페이스로 나타낸다. 기존의 [[http://download.oracle.com/javase/7/docs/api/java/io/File.html|java.io.File]]을 Path로 대체한다. 파일의 경로는 [[http://download.oracle.com/javase/7/docs/api/java/nio/file/Path.html|java.nio.file.Path]] 인터페이스로 나타낸다. 기존의 [[http://download.oracle.com/javase/7/docs/api/java/io/File.html|java.io.File]]을 Path로 대체한다.
줄 21: 줄 22:
 System.out.println("Path exists == " + Files.exists(path)); System.out.println("Path exists == " + Files.exists(path));
 </code> </code>
 +
 +===== Files =====
 +[[http://download.oracle.com/javase/7/docs/api/java/nio/file/Files.html|Files]] 클래스는 파일의 복사/이동/삭제/스트림생성/각종 파일 속성 설정 등에 관련된 매우 쉬운 static 메소드를 수십여개 제공해주고 있다.
 +
 +[[http://www.java7developer.com/blog/?p=334|Manipulating Files in Java 7]]와 [[http://download.oracle.com/javase/tutorial/essential/io/fileio.html|File I/O (Featuring NIO.2) (The Java™ Tutorials > Essential Classes > Basic I/O)]]를 참조한다.
 +
 +[[http://www.javacodegeeks.com/2012/02/java-7-copy-and-move-files-and.html|Java 7: Copy and Move Files and Directories - Java Code Geeks]]
 +
 +[[http://docs.oracle.com/javase/tutorial/essential/io/notification.html|Watching a Directory for Changes (The Java™ Tutorials > Essential Classes > Basic I/O)]]
 +
 +===== Directory 삭제 =====
 +  * [[https://www.baeldung.com/java-delete-directory|Delete a Directory Recursively in Java | Baeldung]]
 +<code java>
 +public void whenDeletedWithNIO2WalkFileTree_thenIsGone() 
 +  throws IOException {
 + 
 +    Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME);
 +
 +    Files.walkFileTree(pathToBeDeleted, 
 +      new SimpleFileVisitor<Path>() {
 +        @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("Directory still exists", 
 +      Files.exists(pathToBeDeleted));
 +}
 +</code>
 +
 +
java/7/files.1316005860.txt.gz · 마지막으로 수정됨: 2011/09/14 22:11 저자 kwon37xi