我尝试使用Windows手机的Microsoft Compression软件包在WP8中打开存储在外部SD卡上的epub。但是,我得到以下异常:
System.IO.InvalidDataException: End of Central Directory record could not be found.
at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
我尝试将手机上的epubs复制到我的电脑上,我可以在那里打开它们作为ziparchives没有任何问题,所以我不相信这些epubs是腐败的。
这是我的代码:
ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
ExternalStorageFile file = await _sdCard.GetFileAsync(path);
if (file != null)
{
using (var zipArchive = new ZipArchive(await file.OpenForReadAsync(), ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
string fileName = Path.GetFileName(entry.Name);
if (!string.IsNullOrEmpty(fileName) && fileName.EndsWith("content.opf"))
{
using (StreamReader reader = new StreamReader(entry.Open()))
{
System.Console.WriteLine(reader.ReadLine());
}
}
}
}
}