Jessu
Jessu

Reputation: 2089

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

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.

Upvotes: 1

Views: 1451

Answers (1)

Maksym Gontar
Maksym Gontar

Reputation: 22775

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
}

Upvotes: 2

Related Questions