从黑莓网址获取数据 [英] get data from url in blackberry
本文介绍了从黑莓网址获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件的URL的http://www.example.com/123.aes(它包含2MB人数超过一个MP3文件的数据)。现在,我想从这个网址获取数据。当我试图HTTP连接获取数据,其显示错误 - 请求实体过大。如何解决这个问题?
我的code为如下 -
I have a url of a file "http://www.example.com/123.aes" ( it contains data of a mp3 file with morethan 2MB). Now i want to fetch the data from this url. When i tried http connection to get data, its showing an error - Requested entity too large. How to solve this problem ?. my code is given below -
try {
HttpConnection httpConn = (HttpConnection) Connector.open(httpURL, Connector.READ, true);
final int iResponseCode = httpConn.getResponseCode();
Dialog.alert(iResponseCode+"");
InputStream is = httpConn.openInputStream();
byte[] data = net.rim.device.api.io.IOUtilities.streamToBytes(is);
String result = new String(data);
Dialog.alert(result);
FileConnection conn = (FileConnection)Connector.open("file:///store/home/user/pictures/"+System.currentTimeMillis()+".mp3", Connector.READ_WRITE);
conn.create();
OutputStream out = conn.openOutputStream();
out.write(data);
out.flush();
out.close();
conn.close();
} catch (IOException e) {
Dialog.alert(e+"");
}
我也想将其保存为MP3文件在手机内存中。
Also i want to save it as mp3 file in phone memory.
推荐答案
最后,我得到了答案 -
Finally I got the answer -
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(httpURL);
HttpConnection httpConn = (HttpConnection) connDesc.getConnection();
try {
httpConn.setRequestMethod(HttpConnection.GET);
InputConnection inputConn = (InputConnection) httpConn;
InputStream is = inputConn.openInputStream();
byte[] data =IOUtilities.streamToBytes(is);
Dialog.alert(original.toString());
FileConnection conn = (FileConnection)Connector.open("file:///store/home/user/pictures/"+System.currentTimeMillis()+".mp3", Connector.READ_WRITE);
conn.create();
OutputStream out = conn.openOutputStream();
out.write(original);
out.flush();
out.close();
conn.close();
} catch (IOException e) {
Dialog.alert(e+"");
}
这篇关于从黑莓网址获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文