我正在尝试从服务器中提取 .jpg 图像,并将其显示为 .jpg和EncodedImage
. ZoomScreen
因为这个 .jpg 可能非常大,所以我想将 .jpg 保存到一个文件中并从那里读取它,所以我没有把整个东西放在内存中。
我面临的问题是 Connector.open("http.url.com/file.jpg") 要么抛出IOException
带有消息“Bad Socket Id”的消息,要么ClassCastException
在我尝试打开 a 时FileConnection
抛出网址。这是我尝试过的一个例子:
try {
FileConnection fileIn = (FileConnection)Connector.open(fileURL);
FileConnection fileOut = (FileConnection)Connector.open(fileDest);
if(!fileOut.exists())
fileOut.create();
InputStream is = fileIn.openInputStream();
OutputStream os = fileOut.openOutputStream();
while(fileIn.canRead() && fileOut.canWrite()){
os.write(is.read());
}
is.close();
os.close();
fileIn.close();
fileOut.close();
EncodedImage image = EncodedImage.getEncodedImageResource(fileDest);
UiApplication.getUiApplication().pushScreen(new ZoomScreen(image));
} catch (Exception e) {
e.printStackTrace();
}
我从 RIM 获得了大部分内容,但我遗漏了一些东西。我知道 url 是正确的,因为当我从同一服务器流式传输音频时,我使用相同的格式。当我尝试连接到服务器时,第一行抛出异常。
有人对此有经验吗?