最近、この回答java.io
に対して、 「純粋な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();
}
(コードは非常に単純化されています:try-finallyとloopを削除しました)
私の質問は、 java.io( ) FileChannel
を使用せずにファイルを読み取るためのまたは他のNIOクラスを取得する方法です。FileInputStream
編集:
Java 6(またはそれ以前のみ)