编程语言
首页 > 编程语言> > Java通过NIO实现快速文件拷贝的代码

Java通过NIO实现快速文件拷贝的代码

作者:互联网

将内容过程重要的内容片段做个记录,下面的内容段是关于Java通过NIO实现快速文件拷贝的内容。

public static void fileCopy( File in, File out )
throws IOException
{
FileChannel inChannel = new FileInputStream( in ).getChannel();
FileChannel outChannel = new FileOutputStream( out ).getChannel();
try
{

long size = inChannel.size();
long position = 0;
while ( position < size )
{
position += inChannel.transferTo( position, maxCount, outChannel );
}
}
finally
{
if ( inChannel != null )
{
inChannel.close();
}
if ( outChannel != null )
{
outChannel.close();
}
}
}




 

标签:Java,NIO,outChannel,inChannel,close,position,拷贝,size
来源: https://www.cnblogs.com/SHUN019/p/10790692.html