我正在尝试从服务器上提取.jpg图像,并将其显示为和
EncodedImage
在一个
ZoomScreen
. 因为这个.jpg文件可能非常大,所以我想把.jpg文件保存到一个文件中,然后从文件中读取它,这样我就不会把整个文件都留在内存中了。
我面临的问题是connector.open(“http.url.com/file.jpg”)正在抛出
IOException
消息“错误的套接字ID”,或者它正在引发
ClassCastException
当我试图打开
FileConnection
指向URL。下面是我尝试过的一个例子:
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是正确的,因为当我从同一个服务器传输音频时使用相同的格式。当我尝试连接到服务器时,在第一行引发了异常。
有人对此有经验吗?