java 大文件copy疑问

项目中需要对大文件(1G,2G... .)进行copy,从A服务器(windows )copy到B服务器(linux ).

 

使用java.io下的BufferedInputStream,BufferedOutputStream来完成。却发现需要2,3个小时才能完成1G文件copy。

为啥需要这么久呢? 两台服务器都在同一个域下。

或者说。。 哪位前辈有这方面的经验。。  期待分享。。。。。。

    private static int BUFFER_SIZE=8*1024;

public static void copyFile(String resourcesPath,String targetPath) throws IOException{
	
		File resourcesFile = new File(resourcesPath);
		File targetFile = new File(targetPath);
		BufferedInputStream input = new BufferedInputStream(new FileInputStream(resourcesFile));   
		BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(targetFile));
	    try {
        	byte[] buffer = new byte[BUFFER_SIZE];
            int n = 0;
            while (-1 != (n = input.read(buffer, 0, BUFFER_SIZE ))) {
            	output.write(buffer, 0, n);
            	output.flush();
            }
        } finally {
        	 if(input!=null){
             	input.close();
             }
            if (output != null) {
            	output.close();
            }
        }
	}
 
output.flush();

放到while中和放到while外应该没有太大的区别把。。。。?

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值