I try to use "jazzlib-j2me-0.0.7.jar" and code
and call itCode: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; }
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 !!!!

Reply With Quote


