Suc*_*ith 2 .net c# xamarin.android xamarin xamarin-studio
我有一个场景,我需要递归解压缩该文件夹.我已经浏览了几个链接但不符合我的要求.我正在使用mono 3.2.6并且需要在android xamarin中递归提取.
我使用了第三方工具ICSharpCode.SharpZipLib.Zip.这在我的调试模式应用程序中工作正常.但在发布模式下抛出错误.在真实设备中安装APK之后.
甚至尝试过Dotnet.Zip,但我无法递归解压缩文件夹. 这里建议开源dll,但它集中在文件而不是文件夹
另一个链接显示了java android中的解决方案,我在c#xamarin android中寻找相同的类型.有没有办法做到这一点,甚至免费的第三方工具都可以.任何人都可以建议我的解决方案或提示表示赞赏.
如果它在Release模式下抛出错误,则可能是因为链接器.要压缩和解压缩文件,您也可以使用
java.util.zip
包.更多信息在这里.
编辑:示例代码
包含命名空间 using Java.Util.Zip;
using ( ZipInputStream s = new ZipInputStream ( File.OpenRead ( strSourcePath ) ) )
{
ZipEntry theEntry;
while ( ( theEntry = s.NextEntry ) != null )
{
string directoryName = Path.GetDirectoryName ( theEntry.Name );
string fileName = Path.GetFileName ( theEntry.Name );
directoryName = Path.Combine ( strDestFolderPath , directoryName );
if ( directoryName.Length > 0 )
{
Directory.CreateDirectory ( directoryName );
}
if ( fileName != String.Empty )
{
using ( FileStream streamWriter = File.Create ( Path.Combine ( strDestFolderPath , theEntry.Name ) ) )
{
int size = 2048;
byte [] data = new byte[size];
while ( true )
{
size = s.Read ( data , 0 , data.Length );
if ( size > 0 )
{
streamWriter.Write ( data , 0 , size );
}
else
{
break;
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
其中strSourcePath是源zip文件路径,strDestFolderPath是目标文件夹路径
| 归档时间: |
|
| 查看次数: |
1409 次 |
| 最近记录: |