【问题标题】:How to download images from a computer ( webserver ) to a phone mobile?如何将图像从计算机(网络服务器)下载到手机?
【发布时间】:2011-08-29 13:09:51
【问题描述】:

我想使用 java j2me 将照片从计算机网络服务器下载到手机移动设备。如何实现?

【问题讨论】:

    标签: java-me


    【解决方案1】:

    使用此方法并传递下载 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);
      }
    

    【讨论】:

    • 如果url目录中的照片不止一张怎么办?
    猜你喜欢
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多