How to retrieve data from a attached zip file in B

2019-04-02 13:48发布

问题:

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
}