您好,我正在使用 Xamarin 和 C# 来制作一个可以压缩和解压缩文件的应用程序,所以经过几次尝试后我找到了 zipStorer。
http://zipstorer.codeplex.com/
这是我的代码
ZipStorer zip = ZipStorer.Open(Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/aaa.zip")), FileAccess.Read);
List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
string path;
foreach (ZipStorer.ZipFileEntry entry in dir)
{
if (Path.GetFileName(entry.FilenameInZip) == "08.jpg")
{
path = Path.Combine(Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/")), Path.GetFileName(entry.FilenameInZip));
zip.ExtractFile(entry, Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/sample.jpg")));
break;
}
}
zip.Close();
几个小时后,代码运行正常并打开 zip 并在控制台中显示所有内容,但没有创建 zip ...我做错了什么吗?
最佳答案
ZipStorer 内部使用字符集 437 进行编码和反编码(ZipStorer.cs 中的第 85 行):
private static Encoding DefaultEncoding = Encoding.GetEncoding(437);
在您构建应用程序时,Xamarin 默认不包含此字符集。如 Localisation And Internationalisation 中所述文档:
为了减小应用程序的大小,Xamarin.iOS 不包含任何特定的编码,您必须指示 mtouch 包含支持所需编码的程序集。
要包含字符集,请通过应用程序中的国际化设置添加 West 字符集:
确保为 Debug 和 Release 检查此项。
当我向我的应用程序添加 zip 支持时,我无法让它为我工作。最后,我通过使用 Java IO 库推出了自己的 zip 支持,但可能有一个组件可用于添加跨平台 zip 支持。
关于android - ZipStorer 不在 Android c# 中创建任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20225175/