从url获取图片

public static File getLogoFromWeb(String logourl, String uploadPath) {
        try {
            URL url = new URL(logourl);
            String fileType = logourl.substring(logourl.lastIndexOf("."), logourl.length());
            File outFile = new File(uploadPath + UUID.randomUUID().toString().replace("-", "") + fileType);
            OutputStream os = new FileOutputStream(outFile);
            InputStream is = url.openStream();
            byte[] buff = new byte[1024];
            while (true) {
                int readed = is.read(buff);
                if (readed == -1) {
                    break;
                }
                byte[] temp = new byte[readed];
                System.arraycopy(buff, 0, temp, 0, readed);
                os.write(temp);
            }
            is.close();
            os.close();
            return outFile;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

posted on 2012-10-23 10:10 Mr.lu 阅读(1421) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2012年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿(2)

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜