Hello Can anybody guide me for fetching Image from Server
Regards
Chandu
Hello Can anybody guide me for fetching Image from Server
Regards
Chandu
Here's to get you going
private Image downloadImage( String url) {
ByteArrayOutStream baos = new ByteArrayOutStream();
try {
// Opening the connection
HttpConnection conn = (HttpConnection)Connector.open(url);
InputStream inputStream = conn.openInputStream();
byte[] nextByte = new byte[1];
//Reading the image byte by byte
while((inputStream.read(nextByte, 0, 1)) != (-1)) {
baos.write(nextByte[0]);
}
//Closing the connection
conn.close();
inputStream.close();
} catch { System.out.println("Downloading image failed"); }
return Image.createImage(baos.toByteArray(), 0, baos.size()); // Creating new image from the fetched byte array
}
Remember to make you HTTP connection in a separate thread and close the connections and streams in a finally block.
[N]/Forum Nokia