public static void fileCopy( File in, File out ) throws IOException { FileChannel inChannel = new FileInputStream( in ).getChannel(); FileChannel outChannel = new FileOutputStream( out ).getChannel(); try { // inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparently has trouble copying large files on Windows // magic number for Windows, 64Mb - 32Kb) int maxCount = (64 * 1024 * 1024) - (32 * 1024); 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(); } } }
使用NIO进行快速的文件拷贝
精选 转载文章标签 使用NIO进行快速的文件拷贝 文章分类 Java 后端开发
上一篇:把 Java util.Date 转成 sql.Date
下一篇:创建图片的缩略图
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
如何防止U盘文件被拷贝?怎样保护U盘文件的安全?
如何防止U盘文件被拷贝?怎样保护U盘文件的安全?
备份文件 用户权限 自动备份