Downloading an Image via HttpConnection (J2ME)?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheMan1
    New Member
    • Mar 2008
    • 19

    #1

    Downloading an Image via HttpConnection (J2ME)?

    How can it be done? Whenever I do it, it downloads a file that is the right size, but seems to be corrupt (ie. can't open it).

    Code:
    				HttpConnection conn = (HttpConnection)Connector.open(url);
    				InputStream fromServer = conn.openInputStream();
    				byte[] theBytes = new byte[(int)conn.getLength()];
    				int i;
    				while ((i = fromServer.read(theBytes)) != -1) {};
    				fromServer.close();
    				conn.close();
    				
    				//create the file.
    				fc.create();
    				fc.setWritable(true);
    				DataOutputStream os = fc.openDataOutputStream();
    				os.write(theBytes);
    				os.flush();
    				os.close();
    				fc.close();
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hey there!

    Are you getting any errors? What happens when you fire the file locally, does it load/opne?

    Let us know...

    Comment

    Working...