import java.io.ioexception,copy文件失败,系统报错:exception:java.io.IOException:存储空间不足,无法处理此命令。...

很奇怪的一个问题,程序在copy文件时报了系统报错:exception:java.io.IOException:存储空间不足,无法处理此命令 错误,结果文件只copy了0字节。但系统中磁盘空间还有20多个G。

具体的程序代码如下所示:

public static void CopyFlie(String srcFilename, String dstFilename)

{

try

{

FileChannel srcChannel =

(new FileInputStream(srcFilename)).getChannel();

FileChannel dstChannel =

(new FileOutputStream(dstFilename)).getChannel();

dstChannel.transferFrom(srcChannel, 0L, srcChannel.size());

srcChannel.close();

dstChannel.close();

}

catch (Exception e)

{

log.error( "copy [ " + srcFilename + "] to [ " + dstFilename + "] except: " + e);

}

}

环境:

操作系统: windows 2000 server SP4

java虚拟机:1.4.2

请路过的朋友发表自己的看法,比较棘手的一个问题?难道是操作系统的bug,还是java的bug?

------解决方法--------------------------------------------------------

我的没有问题

import java.net.*;

import java.util.*;

import java.io.*;

import java.nio.*;

import java.nio.channels.*;

class Test

{

public static void main(String[] args)

{

copyFlie(args[0],args[1]);

}

public static void copyFlie(String srcFilename, String dstFilename)

{

try

{

FileChannel srcChannel =

(new FileInputStream(srcFilename)).getChannel();

FileChannel dstChannel =

(new FileOutputStream(dstFilename)).getChannel();

dstChannel.transferFrom(srcChannel, 0L, srcChannel.size());

srcChannel.close();

dstChannel.close();

}

catch (Exception e)

{

e.printStackTrace();

//log.error( "copy [ " + srcFilename + "] to [ " + dstFilename + "] except: " + e);

}

}

}

java Test C:\1.txt C:\2.txt

------解决方法--------------------------------------------------------

这么大的文件啊,那我没有试过。不过我试用用COS上传组件时也用这个方法进行文件拷贝,也没有出现错误,而且文件是600M大啊。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用腾讯云存储桶下载文件,你可以使用腾讯云提供的 Java SDK。以下是一个简单的示例代码: ```java import com.qcloud.cos.COSClient; import com.qcloud.cos.model.GetObjectRequest; import com.qcloud.cos.model.ObjectMetadata; import com.qcloud.cos.model.ResponseHeaderOverrides; import com.qcloud.cos.model.S3Object; import com.qcloud.cos.transfer.TransferManager; import com.qcloud.cos.transfer.TransferManagerConfiguration; import com.qcloud.cos.transfer.Upload; import com.qcloud.cos.transfer.UploadResult; import com.qcloud.cos.utils.IOUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class TencentCloudStorageExample { private static final String SECRET_ID = "your_secret_id"; private static final String SECRET_KEY = "your_secret_key"; private static final String REGION = "your_region"; private static final String BUCKET_NAME = "your_bucket_name"; private static final String KEY = "your_file_key"; private static final String DOWNLOAD_FILE_PATH = "your_local_file_path"; public static void main(String[] args) throws Exception { COSClient cosClient = new COSClient(SECRET_ID, SECRET_KEY); S3Object s3Object = cosClient.getObject(new GetObjectRequest(BUCKET_NAME, KEY)); InputStream inputStream = s3Object.getObjectContent(); FileOutputStream outputStream = new FileOutputStream(new File(DOWNLOAD_FILE_PATH)); IOUtils.copy(inputStream, outputStream); inputStream.close(); outputStream.close(); cosClient.shutdown(); } } ``` 在这个示例中,我们首先创建了一个 `COSClient` 对象,然后使用 `cosClient.getObject` 方法获取文件的输入流,然后将输入流复制到本地文件中。最后,我们关闭 COSClient 对象来释放资源。 请注意,此示例中使用的密钥和存储桶名称是虚拟的,请替换为你自己的密钥和存储桶名称。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值