How to retrieve data from a attached zip file in Blackberry application?

人盡茶涼 提交于 2019-12-05 09:43:07

问题


I am using eclipse to build application for Blackberry. I attached a zip file with my application. Please help me, I don't know how to retrieve data form the zip file in application development.


回答1:


In BlackBerry we can use two compression standarts: GZip and ZLib. Choose one, then compress your file and add to project. Then you should be able to open it as an resource. After that decompress it with GZIPInputStream or ZLibInputStream accordingly.

Example (uncompress and print text from test.gz attached to project):

try
{
    InputStream inputStream = getClass().getResourceAsStream("test.gz");
    GZIPInputStream gzis = new GZIPInputStream(inputStream);
    StringBuffer sb = new StringBuffer();

    int i;
    while ((i = gzis.read()) != -1)           
    {
        sb.append((char)i);
    }

    String data = sb.toString();
    add(new RichTextField(data));
    gzis.close();
}
catch(IOException ioe)
{
    //do something here
}


来源:https://stackoverflow.com/questions/1357640/how-to-retrieve-data-from-a-attached-zip-file-in-blackberry-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!