Use java.util develop a C#.net zip tools
来源:互联网 发布:巴基斯坦进出口数据 编辑:程序博客网 时间:2024/06/04 18:40
1. Step 1: add reference to vjslib.dll under C:/$WIDOWS DIRECTORY$/Microsoft.NET/Framework/$VERSION NUMBER $/
2. using
///
<summary>/// Zip single file
/// </summary>
/// <param name="FilePath">original file path : string like "c://intrafinity//web//scorm//"</param>
/// <param name="FileName">original file name: string like "win2000.gif"</param>
/// <param name="ZipFileName">zipped file : string like "c://intrafinity//web//scorm//new.zip"</param>public static void ZipFile(string FilePath, string FileName, string ZipFileName)
{ZipOutputStream os = new ZipOutputStream(new java.io.FileOutputStream(ZipFileName));
ZipEntry ze = new ZipEntry(FileName);
ze.setMethod(ZipEntry.DEFLATED);
os.putNextEntry(ze);
java.io.
FileInputStream fs = new java.io.FileInputStream(string.Concat(FilePath,FileName));sbyte[] buff = new sbyte[1024];
int n = 0;while ((n = fs.read(buff, 0, buff.Length)) > 0)
{os.write(buff, 0, n);}
fs.close();
os.closeEntry();
os.close();
}
/// <summary>
/// Zip folder
/// </summary>
/// <param name="FolderName">folder name : string like "c://intrafinity//web//scorm//"</param>
/// <param name="ZipFileName">zipped file: string like "c://intrafinity//web//s.zip"</param>
public static void ZipFolder(string FolderName, string ZipFileName)
{ZipOutputStream os = new ZipOutputStream(new java.io.FileOutputStream(ZipFileName));
ZipFolder(FolderName, ZipFileName, "", os);
os.closeEntry();
os.close();
}
public static void ZipFolder(string FolderName, string ZipFileName, string Addon, ZipOutputStream os){string[] strs1 = Directory.GetFiles(FolderName);
string[] strs2 = Directory.GetDirectories(FolderName);for (int i = 0; i < (int)strs1.Length; i++)
{
string str1 = strs1[i];
FileInfo fileInfo = new FileInfo(str1);
ZipEntry ze = new ZipEntry(string.Concat(Addon,fileInfo.Name));
ze.setMethod(ZipEntry.DEFLATED);
os.putNextEntry(ze);
java.io.
FileInputStream fs = new java.io.FileInputStream(string.Concat(FolderName, fileInfo.Name));sbyte[] buff = new sbyte[1024];
int n = 0;while ((n = fs.read(buff, 0, buff.Length)) > 0)
{
os.write(buff, 0, n);
}
fs.close();
}
{
string str2 = strs2[j];
DirectoryInfo directoryInfo = new DirectoryInfo(str2);
ZipFolder(
string.Concat(FolderName, directoryInfo.Name, "//"), ZipFileName, string.Concat(Addon, directoryInfo.Name,"//"), os);}
}
4. Notice: .NET Framework 1.1 and 1.0 have some bug with vjslib.dll, the zipped file will have some head errors, but the content is fine, it can still be opened by winzip and winrar, but you will have some problem when open the zipped file by using wjslib.dll in your code. Ironic?
Framework 2.0 fixed the problem.
5. another solution is http://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/default.aspx
- Use java.util develop a C#.net zip tools
- org.apache.tools.zip包解决java.util.zip包中文问题
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- Develop Smartphone Device use VS.NET 2003
- java.util.zip
- java.util.zip
- java.util.zip.ZipException
- RS232 Serial Comm (Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications)
- java.util.zip对zip文件解压
- java.util.zip.ZipFile翻译
- java.util.zip.ZipInputStream翻译
- java.util.zip.ZipOutputStream翻译
- java.util.zip.ZipException翻译
- java.util.zip.ZipEntry翻译
- DEBUG < this.txt Generate this.com
- 无敌命令 几乎清除所有进程
- ASP.NET实现无刷新的DropdownList联动效果(20041204)
- 期待《魔兽世界》内测帐号
- 深爱过的,永远深爱的亲人
- Use java.util develop a C#.net zip tools
- [转]我与华罗庚
- Oracle PL/SQL入门之慨述
- 最美妙的英文单词大排名
- 读的一则故事的感想
- 使用Thread Pooling处理简短任务
- 函数型科学计算器NGNcalc2下载详情况
- NGNc“零移植”开发伙伴计划
- 又再次的漂走了,到了新的地方