パッケージには、読んで、 輸入java.io. *; 輸入java.nio.MappedByteBuffer; 輸入java.nio.channels.FileChannelの。 / ** * 2019年9月23日にジョイスによって作成されます。 * / publicクラスFormerReader { 公共の静的な無効メイン(文字列[] F)例外{スロー fileInファイル=新しいファイル( "/ユーザ/ジョイス/ダウンロード/ java.pdf")と、//打开源文件 fileOut =新しいファイルをファイル( "/ユーザ/ジョイス/ダウンロード/ target.pdf"); //普通ストリーム方式 長いformerStart =にSystem.currentTimeMillis(); FileInputStreamのstreamln =新しいFileInputStreamを(fileIn)。 FileOutputStream streamOut =新しいのFileOutputStream(fileOut)。 int型のC; (!(C = streamln.read())= -1){一方 streamOut.write(C); } streamln.close()。 streamOut.close(); 長いformerEnd =にSystem.currentTimeMillis(); System.out.println((formerStart-formerEnd)/ 1000)。 // NIOれるMappedByteBuffer formerStart =にSystem.currentTimeMillis(); 長いLEN = fileIn.length()。 FileChannelのFileChannel =新規のRandomAccessFile(fileIn、 "R")さらに、getChannel()。 れるMappedByteBufferれるMappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY、0、LEN)。 れるMappedByteBuffer mappedByteBufferout =新規のRandomAccessFile(fileOut、 "RW")さらに、getChannel()マップ(FileChannel.MapMode.READ_WRITE、0、LEN)。 {(; <LENオフセットオフセット++ 0 =オフセットINT)のための バイトb = mappedByteBuffer.get()。 mappedByteBufferout.put(B)。 } formerEnd =にSystem.currentTimeMillis(); System.out.println((formerStart-formerEnd)/ 1000)。 } }
-283
0
ファイル26M