请问各位大佬,这个代码对于一定字节以上的文件为何会导致输出文件相当大(能达到1个多G)

Queen_ZiLuoHeng 2018-05-25 10:26:21
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyDemo01 {
public static void copyImageFile(String filepath,String targetpath) {
try {
FileInputStream fis = new FileInputStream(filepath);
BufferedInputStream bis= new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream(targetpath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int len = 0;
byte[] b = new byte[2048];
try {

while((len = bis.read(b))!=-1) {
bos.write(b,0,len);
}
bis.close();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
copyImageFile("icon.png","copyIcon.png");
}

}
...全文
189 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjsl__ 2018-05-25
  • 打赏
  • 举报
回复
可以在while循环里输出循环次数,计算一下应当循环几次

58,453

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧