首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解压/解压blackberry中的Zip文件

解压/解压blackberry中的Zip文件
EN

Stack Overflow用户
提问于 2012-07-02 16:22:03
回答 1查看 1.2K关注 0票数 3

我有一个包含文件夹的压缩文件,里面有一些图像文件,我希望解压这些images.However,但我一直找不到任何东西。我一直在查看zipMe,但找不到任何相关的帮助。

下面是我到目前为止开发的代码。

代码语言:javascript
复制
    ZipEntry dataZE;
    InputStream isData;
    StringBuffer sbData;
    ZipInputStream dataZIS;

    String src = "file:///store/home/user/images.zip";
    String path = "file:///store/home/";
    String fileName = "";
    FileConnection f_Conn;

    public UnZipper() {

        debugger("Unzipper constructor");

        try {
            f_Conn = (FileConnection) Connector.open(src);
        } catch (IOException e) {
            debugger("f_conn error :" + e.getMessage());
        }

        try {
            isData = f_Conn.openInputStream();
        } catch (IOException e) {
            debugger("f_conn error getting ip_stream:" + e.getMessage());
        }

        sbData = new StringBuffer();

        dataZIS = new ZipInputStream(isData);

        debugger("got all thing initialized");

    }

    public void run() {

        debugger("unzipper run");

        try {
            startUnziping();
        } catch (IOException e) {

            debugger("Error unzipping " + e.getMessage());
        }

        debugger("finished...");

    }


    private void startUnziping() throws IOException {

        debugger("startUnziping");
        dataZE = dataZIS.getNextEntry();
        fileName = dataZE.getName();
        writeFile();
        dataZIS.closeEntry();

        debugger(">>>>>>>>>>> : " + fileName);
    }

    private void readFile() throws IOException {

        debugger("readFile");
        int ch;
        int i = 0;
        while ((ch = dataZIS.read()) != -1) {

            debugger((i++) + " : " + sbData.toString()
                    + " >>> writting this..");
            sbData.append(ch);
        }

    }

    private void writeFile() {

        debugger("writting file...");
        FileConnection f_Conn = null;
        byte[] file_bytes = new byte[sbData.length()];
        file_bytes = sbData.toString().getBytes();

        try {
            readFile();
        } catch (IOException e) {
            debugger("Error while reading " + e.getMessage());
        }

        try {
            f_Conn = (FileConnection) Connector.open(path + fileName);
        } catch (IOException e) {
            debugger("getting f_conn" + e.getMessage());
        }

        if (!f_Conn.exists()) {
            // create the file first
            debugger("I know file does not exists");
            try {
                f_Conn.mkdir();
            } catch (IOException e) {
                debugger("Oops!!! error creating fle : " + e.getMessage());
            }
        }
        try {
            f_Conn.setWritable(true);
            debugger("file is nt writeable");
        } catch (IOException e) {
            debugger("cannot make it writeable : " + e.getMessage());
        }
        OutputStream lo_OS = null;
        try {
            lo_OS = f_Conn.openOutputStream();
            debugger("got out Stream hero!!!");
        } catch (IOException e) {
            debugger("cant get out Stream !!!");
        }
        try {
            lo_OS.write(file_bytes);
            debugger("yess...writtent everything");
        } catch (IOException e) {
            add(new LabelField("Error writing file ..." + e.getMessage()));
        }
        try {
            lo_OS.close();
            debugger("now closing connection...");
        } catch (IOException e) {
            debugger("error closing out stream : " + e.getMessage());
        }

    }
}

我已经能够得到包含图像的ZipEntry表示文件夹,但是我还不能计算出我必须如何提取这些图像。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-03 00:35:24

startUnzipping中迭代压缩文件中的所有ZipEntry (您只使用代码中的第一个)。子文件对应的项目名称应该类似于"foldername/filename".

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11290051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档