• 从远程服务器上下载图片代码


    //urlList是远程图片地址,path是图片下载后将要存放的地址

    private static void downloadPicture(String urlList,String path) {
    URL url = null;
    try {
    url = new URL(urlList);
    DataInputStream dataInputStream = new DataInputStream(url.openStream());

    FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    byte[] buffer = new byte[1024];
    int length;

    while ((length = dataInputStream.read(buffer)) > 0) {
    output.write(buffer, 0, length);
    }
    fileOutputStream.write(output.toByteArray());
    dataInputStream.close();
    fileOutputStream.close();
    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

  • 相关阅读:
    软件设计中的立足点
    Clojure基础
    团队凝聚力
    执行力与领导力
    工作与生活
    分离焦虑OR责任焦虑
    保持激情
    立足点
    论研发管理--开篇
    初级码农常犯错误
  • 原文地址:https://www.cnblogs.com/wth21-1314/p/10064684.html
Copyright © 2020-2023  润新知