gpt4 book ai didi

android - xamarin ionic zip 解压缩导致错误

转载 作者:行者123 更新时间:2023-11-30 03:20:05 25 4
gpt4 key购买 nike

我有以下方法在下载后解压缩文件。但它以错误结束

System.ArgumentException Path is empty at System.IO.Directory.CreateDirectory System.String path 0x00000 in file unknown at ionic.zip.zipentry.internalExtract system.string basedir system.io.stream outstream system.string password 0x00000 in filname unknown.

zip 文件没有密码,可以打开,例如带安卓压缩包

public void ExtractBilderZip()
{
string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string unzipziel = Path.Combine(documentsPath, "Bilder");

// if Bilder does not exist create subdirectory
if (Directory.Exists(unzipziel)==false)
{
var directoryname = Path.Combine(documentsPath, "Bilder");
Directory.CreateDirectory(directoryname);

}

//////////////////////////////////////////////////////
string zipToUnpack = localPathB; //localPathB ist the zipFile name including path

// I tried with and wihout the following 2 lines which makes no diffence
zipToUnpack = zipToUnpack.Replace('/', Path.DirectorySeparatorChar);
unzipziel = unzipziel.Replace('/', Path.DirectorySeparatorChar);

try
{
ZipFile zip1 = ZipFile.Read(zipToUnpack);

zip1.ExtractAll(unzipziel,ExtractExistingFileAction.OverwriteSilently);
}
catch (System.Exception ex1)
{
//System.Console.Error.WriteLine("exception: " + ex1);
for (int i = 0; i < 10; i++)
{
Toast.MakeText(this, "exception: " + ex1, ToastLength.Long).Show();
}
}
}

最佳答案

我通过使用通过 google 找到的名为 ZipStorer 的类解决了我的问题。我在这里找到它:zipstorer.codeplex.com它很小而且非常容易使用!!

FileInfo fi = new FileInfo(zipToUnpack);

FileStream inFile = fi.OpenRead();

// Get original file extension,
// for example "doc" from report.doc.cmp.
string curFile = fi.FullName;
string origName = unzipziel;

try
{
// Opens existing zip file
ZipStorer zip = ZipStorer.Open(localPathB, FileAccess.Read);

// Read all directory contents
List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

// Extract all files in target directory
string path;
bool result;
foreach (ZipStorer.ZipFileEntry entry in dir)
{
path = Path.Combine(unzipziel, Path.GetFileName(entry.FilenameInZip));
result = zip.ExtractFile(entry, path);

RunOnUiThread(() =>
{
Button buttonUZ = FindViewById<Button>(Resource.Id.btnUnzip);
buttonUZ.Text = "Entpacke: " + entry.FilenameInZip;

});
}
zip.Close();

File.Delete(@localPathB);
}
catch (Exception ex1)
{
var errorActivity = new Intent(this, typeof(ErrorActivity));
errorActivity.PutExtra("ERROR", ex1.ToString());

StartActivity(errorActivity);
}

关于android - xamarin ionic zip 解压缩导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19314900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com