BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-29-2010, 01:02 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Dec 2009
Location: Sri Lanka
Model: 9000
PIN: N/A
Carrier: Software Engineer
Posts: 21
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Download Files

Please Login to Remove!

Hi,

Currently I am developing an application which let users to download MP3 files from a web server. As well as I am downloading images, XML files from the same web server. However images and XML files downloading without any bug. I downloaded 250 KB image as well. But when I trying to download MP3 files it's not working. May be time out. I don't know exactly. Is there any way to do this. Any sample source code available. I will put my source code method here for further details. This code works fine for all XML and Image files which I downloaded so far.

public void downloadAlbumImage(String AlbumID, String imgURL)
{try {HttpConnection connection = null;InputStream inputStream = null;connection = (HttpConnection) Connector.open(imgURL , Connector.READ_WRITE, true);inputStream = connection.openInputStream();FileConnection dest = (FileConnection)Connector.open(getRootFileSystem(A NY_STORAGE_ENGINE) +SystemSettings.strParentDirectory + SystemSettings.strOfflineImageDirectory + AlbumID + SystemSettings.strStoredImageExtension,Connector.R EAD_WRITE);if (!dest.exists()) {dest.create(); }OutputStream outStream = dest.openOutputStream();byte[] Buffer = new byte[1024];int length = -1; while ((length = inputStream.read(Buffer)) > 0) {outStream.write(Buffer, 0 , length); }outStream.close();} catch ( Exception e ) {}}
public void downloadAlbumImage(String AlbumID, String imgURL)
{
try {
HttpConnection connection = null;InputStream inputStream = null;

connection = (HttpConnection) Connector.open(imgURL , Connector.READ_WRITE, true);

inputStream = connection.openInputStream();FileConnection dest = (FileConnection)Connector.open(getRootFileSystem(A NY_STORAGE_ENGINE) +SystemSettings.strParentDirectory + SystemSettings.strOfflineImageDirectory + AlbumID + SystemSettings.strStoredImageExtension,Connector.R EAD_WRITE);

if (!dest.exists()) {
dest.create();
}

OutputStream outStream = dest.openOutputStream();

byte[] Buffer = new byte[1024];
int length = -1;
while ((length = inputStream.read(Buffer)) > 0) {
outStream.write(Buffer, 0 , length);
}
outStream.close();


} catch ( Exception e ) {
}}
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.