How to download images from a computer ( webserver ) to a phone mobile?

China☆狼群 提交于 2020-01-25 12:29:45

问题


I want to download photos from a computer webserver to a phone mobile device by using java j2me. How to achieve that ?


回答1:


Use this method and pass the download URL.

private Image getImage(String url) throws IOException
  {
    ContentConnection connection = (ContentConnection) Connector.open(url);
    DataInputStream iStrm = connection.openDataInputStream();
    ByteArrayOutputStream bStrm = null;    
    Image im = null;

    try
    {
      byte imageData[];
      int length = (int) connection.getLength();
      if (length != -1)
      {
        imageData = new byte[length];  
        iStrm.readFully(imageData);
      } else {       
        bStrm = new ByteArrayOutputStream();
        int ch;
        while ((ch = iStrm.read()) != -1)
          bStrm.write(ch);
        imageData = bStrm.toByteArray();
        bStrm.close();                
      }
      im = Image.createImage(imageData, 0, imageData.length);        
    }
    finally
    {
      // Clean up
      if (iStrm != null)
        iStrm.close();
      if (connection != null)
        connection.close();
      if (bStrm != null)
        bStrm.close();                              
    }
    return (im == null ? null : im);
  }


来源:https://stackoverflow.com/questions/7226245/how-to-download-images-from-a-computer-webserver-to-a-phone-mobile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!