최근에이 answer에 "pure NIO"를 사용하려면 java.io
에서 멀리 떨어져 있어야한다는 의견이있었습니다.
는 단순화 된 코드 (파일을 복사)되는이 :java.io. *을 사용하지 않고 FileChannel 가져 오기 (순수 NIO 사용)
private static void copy(File source, File destination) throws IOException {
long length = source.length();
FileChannel input = new FileInputStream(source).getChannel();
FileChannel output = new FileOutputStream(destination).getChannel();
input.transferTo(0, length, output);
output.close();
input.close();
}
(코드 매우 단순화 : 제거 마지막으로-시도하고 루프)
내 질문 얻는 방법이다 FileChannel
또는 기타 java.io (FileInputStream
)를 사용하지 않고 파일을 읽는 NIO 클래스?
편집 :
자바 6