zipping files in C#
-
Hi, What library do you use to zip up files? I am using java.util.zip and it's giving me some problems. Everything works fine if WInZip is installed. However if you uninstall WinZip and it uses the Windows default compresser things don't work so well: the zip file is created but it's empty. Does anyone know a solution to this problem? Thanks, Elena Here is my code:
ZipOutputStream m_zipstream; string filepath = @"C:\Elena\Junk\test\a.txt"; m_zipstream = new ZipOutputStream( new java.io.FileOutputStream( @"C:\Elena\Junk\test\zip.zip" ) ); ZipEntry currententry = new ZipEntry(filepath); currententry.setMethod(ZipEntry.DEFLATED); m_zipstream.putNextEntry(currententry); try { java.io.FileInputStream current = new java.io.FileInputStream(filepath); try { sbyte[] buffer = new sbyte[8192]; int buffercount; while ((buffercount = current.read(buffer, 0, buffer.Length)) > 0) m_zipstream.write(buffer, 0, buffercount); } finally { current.close(); } } finally { m_zipstream.closeEntry(); } m_zipstream.close(); m_zipstream = null;
Elena -
Hi, What library do you use to zip up files? I am using java.util.zip and it's giving me some problems. Everything works fine if WInZip is installed. However if you uninstall WinZip and it uses the Windows default compresser things don't work so well: the zip file is created but it's empty. Does anyone know a solution to this problem? Thanks, Elena Here is my code:
ZipOutputStream m_zipstream; string filepath = @"C:\Elena\Junk\test\a.txt"; m_zipstream = new ZipOutputStream( new java.io.FileOutputStream( @"C:\Elena\Junk\test\zip.zip" ) ); ZipEntry currententry = new ZipEntry(filepath); currententry.setMethod(ZipEntry.DEFLATED); m_zipstream.putNextEntry(currententry); try { java.io.FileInputStream current = new java.io.FileInputStream(filepath); try { sbyte[] buffer = new sbyte[8192]; int buffercount; while ((buffercount = current.read(buffer, 0, buffer.Length)) > 0) m_zipstream.write(buffer, 0, buffercount); } finally { current.close(); } } finally { m_zipstream.closeEntry(); } m_zipstream.close(); m_zipstream = null;
Elena