如何将图像从计算机(网络服务器)下载到手机上? [英] How to download images from a computer ( webserver ) to a phone mobile?

查看:68
本文介绍了如何将图像从计算机(网络服务器)下载到手机上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Java j2me将照片从计算机的网络服务器下载到手机上.如何实现呢?

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

推荐答案

使用此方法并传递下载URL.

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);
  }

这篇关于如何将图像从计算机(网络服务器)下载到手机上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆