wp7 利用ZipOutputStream压缩.txt文件问题

June1991 2011-12-22 09:55:14
//压缩
private static void CreateZipFile(string filesPath, string zipFilePath)
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isf.FileExists(filesPath))//判断文件夹是否存在
{
MessageBox.Show("文件夹不存在");
}
}
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isf.DirectoryExists(Used.strSignInPath))//判断文件是否存在
{
MessageBox.Show("文件不存在");
return;
}
string[] filenames = isf.GetFileNames(filesPath);
try
{
using (ZipOutputStream s = new ZipOutputStream(isf.CreateFile(zipFilePath)))
{
s.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(file);
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
文件夹和.txt文件都是用IsolatedStorageFile创建的为什么压缩不成功呢?
...全文
110 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
June1991 2011-12-23
  • 打赏
  • 举报
回复
 using (var fs = isf.OpenFile(file,FileMode.OpenOrCreate,FileAccess.Read))
June1991 2011-12-23
  • 打赏
  • 举报
回复

private static void CreateZipFile(string filesPath, string zipFilePath)
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] filenames = isf.GetFileNames(filesPath);
try
{
using (ZipOutputStream s = new ZipOutputStream(isf.CreateFile(zipFilePath)))
{
s.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(file);
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}


using (FileStream fs = File.OpenRead(file))
到这里就无法执行了!
DrSmart 2011-12-22
  • 打赏
  • 举报
回复
嗨,wp7解压东西太可怜了
June1991 2011-12-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 drsmart 的回复:]
嗨,wp7解压东西太可怜了
[/Quote]
我不是解压 是压缩

7,659

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧