求助?????急急急??????java IO流问提??????????? 哪位GGJJ能帮我实现下面功能: 将一张JPG的图片从一个目录下面复制到另一个目录下? 谢谢各位GGJJ 在线等待。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 InputStream input = new BufferedInputStream(new FileInputStream(new File("D:\\pic175.jpg"))); byte[] buf = new byte[1024*1024]; int len = 0; OutputStream output = new BufferedOutputStream(new FileOutputStream(new File("D:\\upload\\pic175.jpg"))); while((len = input.read(buf)) >0) output.write(buf,0,len); input.close(); output.close();我自己搞定了 给大家参考了。 需要注意一点:先声明InputStream和OutputStream为null,然后在try里面初始化,最后在finally里面close。如下:InputStream in = null;OutputStream out = null;try{ in = new BufferedInputStream(new FileInputStream(new File("D:\\pic175.jpg"))); out = new BufferedOutputStream(new FileOutputStream(new File("D:\\upload\\pic175.jpg"))); ...}catch (Exception e){}finally{ if (in != null) { try { in.close(); } catch (Exception e) {} } if (out != null) { try { out.close(); } catch (Exception e) {} }} 请教达人,在struts中怎样实现下载功能,谢谢!! myeclipse连接sqlserver2005报错不知道什么原因? ssh下配置OpenSessionInViewFilter的问题 jsp模糊查找的疑问,有代码!!! 如何在MyEclipse中创建Tomcat工程 每个局部变量在用完之后都要free掉吗? Java区人气提升活动之二 —— 排序抢答 oracle 8i 数据库连接问题 请教tomcat中的class问题(立即送分) 各位高手,谁能帮我解决这个问题?我很头疼~!多谢了~! struts错误,高手请进 广域网发布JSP程序
byte[] buf = new byte[1024*1024];
int len = 0; OutputStream output = new BufferedOutputStream(new FileOutputStream(new File("D:\\upload\\pic175.jpg")));
while((len = input.read(buf)) >0)
output.write(buf,0,len);
input.close();
output.close();我自己搞定了
给大家参考了。
OutputStream out = null;try
{
in = new BufferedInputStream(new FileInputStream(new File("D:\\pic175.jpg")));
out = new BufferedOutputStream(new FileOutputStream(new File("D:\\upload\\pic175.jpg"))); ...
}
catch (Exception e)
{
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (Exception e)
{}
}
if (out != null)
{
try
{
out.close();
}
catch (Exception e)
{}
}
}