문서의 이전 판입니다!
NIO. 2 에 파일 관련 각종 API가 추가되었다. 이전보다 더 쉽게 파일 관련 작업을 수행할 수 있다.
File I/O (Featuring NIO.2) (The Java™ Tutorials > Essential Classes > Basic I/O) 에서 자세히 볼 수 있으며 아래는 간단한 정리이다..
파일의 경로는 java.nio.file.Path 인터페이스로 나타낸다. 기존의 java.io.File을 Path로 대체한다.
Path 는 인터페이스이며 Paths 혹은 FileSystem 객체로부터 Path 객체를 생성할 수 있다.
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; Path path = Paths.get("C:\\Temp\\test.txt"); //혹은 FileSystem 객체로 부터... // Path pathFromFS = FileSystems.getDefault().getPath("C:\\Temp\\test.txt"); System.out.println("Path exists == " + Files.exists(path));