首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 上载图片代码

2012-12-25 
java 下载图片代码?package webconimport java.io.BufferedInputStreampublic class MakeImage {// 生成

java 下载图片代码

?

package webcon;import java.io.BufferedInputStream;public class MakeImage {// 生成图片函数public  void makeImg(String imgUrl,String fileURL) {try {// 创建流BufferedInputStream in = new BufferedInputStream(new URL(imgUrl).openStream());// 生成图片名int index = imgUrl.lastIndexOf("/");String sName = imgUrl.substring(index+1, imgUrl.length());System.out.println(sName);// 存放地址File img = new File(fileURL+sName);// 生成图片BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(img));byte[] buf = new byte[2048];int length = in.read(buf);while (length != -1) {out.write(buf, 0, length);length = in.read(buf);}in.close();out.close();} catch (Exception e) {e.printStackTrace();}}}

热点排行