我有一个文件的网址“http://www.example.com/123.aes”(它包含超过2MB的mp3文件的数据)。现在我想从这个网址获取数据。当我尝试 http 连接来获取数据时,它显示错误 -请求的实体太大。如何解决这个问题呢 ?。
我的代码如下 -
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 文件在手机内存中。
希望对你有帮助。尝试以下功能:
public static String getPage(String url) {
String response = "";
try {
HttpConnection conn =
(HttpConnection)Connector.open(url,Connector.READ_WRITE);
InputStream input =conn.openInputStream();
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
while( -1 != (len = input.read(data))) {
raw.append(new String(data, 0, len));
}
response = raw.toString();
input.close();
}
catch(Exception e) {
Dialog.alert(e.toString());
}
return response;
}
调用此函数的示例,
getPage("yourUrl;deviceside=true;interface=wifi");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)