//ps:下面是在网上down的一段要实现压缩的代码,在pc端做winform程序时测试成功,但是把代码移到wince环境就有问题?
//问题:执行到这句的时候zipoutputstream.PutNextEntry(entry);//提示:未找到方法: get_CurrentCulture System.Threading.Thread。
//希望各位高手指点!
private string zipfilecreatename = @"\Program Files\writer";
private string filesdirectorypath = @"\Program Files\writer";
private int dirnamelength = 0;
private int ziplevel = 6;
///
/// 压缩文件
///
///
public void ZipFileCreate()
{
ZipOutputStream zipoutputstream = new ZipOutputStream(File.Create(@"\Program Files\writer.zip"));
zipoutputstream.SetLevel(this.ziplevel);
Crc32 crc = new Crc32();
Hashtable fileList = this.getAllFies();
foreach (DictionaryEntry item in fileList)
{
FileStream fs = File.OpenRead(item.Key.ToString());
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(item.Key.ToString().Substring(this.filesdirectorypath.Length - this.dirnamelength));
entry.DateTime = (DateTime)item.Value;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
zipoutputstream.PutNextEntry(entry);//问题:未找到方法: get_CurrentCulture System.Threading.Thread。
zipoutputstream.Write(buffer, 0, buffer.Length);
}
zipoutputstream.Finish();
zipoutputstream.Close();
}
///
/// 获取一个文件夹下的所有文件夹里的文件
///
///
///
private void getAllDirsFiles(DirectoryInfo[] dirs, Hashtable filesList)
{
foreach (DirectoryInfo dir in dirs)
{
foreach (FileInfo file in dir.GetFiles("*.*"))
{
filesList.Add(file.FullName, file.LastWriteTime);
}
this.getAllDirsFiles(dir.GetDirectories(), filesList);
}
}
///
/// 获取所有文件
///
///
private Hashtable getAllFies()
{
Hashtable FilesList = new Hashtable();
DirectoryInfo fileDire = new DirectoryInfo(this.filesdirectorypath);
if (!fileDire.Exists)
{
throw new System.IO.FileNotFoundException("目录:" + fileDire.FullName + "没有找到!");
}
this.dirnamelength = fileDire.Name.Length;
this.getAllDirFiles(fileDire, FilesList);
this.getAllDirsFiles(fileDire.GetDirectories(), FilesList);
return FilesList;
}
///
/// 获取一个文件夹下的文件
///
///
目录名称
///
文件列表HastTable
private void getAllDirFiles(DirectoryInfo dir, Hashtable filesList)
{
foreach (FileInfo file in dir.GetFiles("*.*"))
{
filesList.Add(file.FullName, file.LastWriteTime);
}
}