×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    23

    Unhappy j2me - How can zip and unzip on j2me ?????

    I try to use "jazzlib-j2me-0.0.7.jar" and code

    Code:
    public void zipBytes(String filename, byte[] input) throws IOException {
            FileConnection fnn = (FileConnection) Connector.open("file:///e:/TestZip.zip", Connector.READ_WRITE);
            fnn.create();
            ZipOutputStream zos = new ZipOutputStream(fnn.openDataOutputStream());
            ZipEntry entry = new ZipEntry(filename);
            entry.setSize(input.length);
            zos.putNextEntry(entry);
            zos.write(input);
            zos.closeEntry();
            zos.close();
        }
    
        public byte[] getByteDAta() {
            byte[] imageData = new byte[0];
            try {
                int CHUNK_SIZE = 1024;
                InputStream fis = null;
                String path = "file:///e:/ABCDEG.log";
                FileConnection fileConn = (FileConnection) Connector.open(path, Connector.READ_WRITE);
                try {
                    fileConn = (FileConnection) Connector.open(path);
                } catch (Exception e) {
                    Logger.printErrorln("Exception " + e);
                    fileConn = (FileConnection) Connector.open(path, Connector.READ_WRITE);
                }
    
                fis = fileConn.openInputStream();
                long overallSize = fileConn.fileSize();
                Logger.printErrorln(" fileConn.fileSize = " + fileConn.fileSize());
                int length = 0;
    
                while (length < overallSize) {
                    byte[] mdata = new byte[CHUNK_SIZE];
                    int readAmount = fis.read(mdata, 0, CHUNK_SIZE);
                    byte[] newImageData = new byte[imageData.length + CHUNK_SIZE];
                    System.arraycopy(imageData, 0, newImageData, 0, length);
                    System.arraycopy(mdata, 0, newImageData, length, readAmount);
                    imageData = newImageData;
                    length += readAmount;
                }
                fis.close();
                fileConn.close();
            } catch (Exception e) {
            }
            return imageData;
    
        }
    and call it
    try {
    zipBytes("ABCDEG.log", getByteDAta());
    } catch (IOException ex) {
    ex.printStackTrace();
    }

    but it throw a exception :
    java.io.IOException: failed to write to file
    at com.nokia.mid.impl.isa.io.protocol.external.storage.Protocol$FileConnectionOutputStream.write(+86)
    at java.io.DataOutputStream.write(+10)
    at java.io.OutputStream.write(+8)
    at net.sf.jazzlib.ZipOutputStream.putNextEntry(+389)
    at App.TestZI.zipBytes(+56)
    at App.TestZI$1.run(+16)
    at com.sun.lwuit.Display.processSerialCalls(+107)
    at com.sun.lwuit.Display.mainEDTLoop(+57)
    at com.sun.lwuit.RunnableWrapper.run(+245)


    Please help me !!!!

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: j2me - How can zip and unzip on j2me ?????

    You might not have access to - file:///e:/TestZip.zip on the device, try to use the default photo/images folder on the device. Try to run Sun WTK22 - PDAPDemo - File connection example and see the path on which you are able to create(read/write) the files and folders on the device.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    23

    Re: j2me - How can zip and unzip on j2me ?????

    I tried but i can't write "zip file" in any folder.I can write *.mp3 file, *.txt file but i can't write *.zip file

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1

    Re: j2me - How can zip and unzip on j2me ?????

    hi
    am got the same exception.
    Can anyone help me how to reslove this exception ?
    @ thanhlnh : can you please tell how was your problem sloved ?

  5. #5
    Registered User
    Join Date
    Mar 2013
    Location
    United Kingdom
    Posts
    161

    Re: j2me - How can zip and unzip on j2me ?????

    Quote Originally Posted by madhurij2me View Post
    hi
    am got the same exception.
    Can anyone help me how to reslove this exception ?
    @ thanhlnh : can you please tell how was your problem sloved ?
    Can you give us a sample of your code?

Similar Threads

  1. How to unzip a password protected zip file
    By inigonirmal in forum Symbian
    Replies: 1
    Last Post: 2011-03-24, 10:59
  2. j2me zip/unzip, jar/unjar
    By raxitsheth in forum Mobile Java General
    Replies: 3
    Last Post: 2010-10-25, 15:39
  3. How to unzip large zip file
    By raf1hh in forum Symbian
    Replies: 11
    Last Post: 2009-06-24, 21:00
  4. zip/unzip files
    By mobileworm in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2006-02-17, 06:21
  5. Unzip problem with nS60_sdk_v1_2.zip
    By arsih in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2003-11-20, 10:05

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×