我的 Assets 文件夹中有一个 zip 文件,当我试图将此文件复制到外部下载文件夹时,我无法打开它。似乎文件复制没有完成,因为它比应该的少了几 kb。
我正在使用以下代码来实现这一点:
using (Stream stream = activity.Assets.Open (PINPAD_FOLDER + "/" + file))
{
stream.CopyTo (System.IO.File.Create (outputPath));
stream.Close ();
}
输出文件夹是:
string outputPath = Path.Combine (Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filename);
我所需要的只是从我的应用程序中获取此 zip 文件的路径,这似乎无法从 Asset 目录中获取,因为我们只能返回一个流。因此,我必须将它复制到我知道其路径的目录中。
最佳答案
试试这个
using (Stream stream = activity.Assets.Open (PINPAD_FOLDER + "/" + file))
{
using(var fileStream = System.IO.File.Create (outputPath))
{
stream.CopyTo(fileStream );
}
}
关于android - Assets 复制未完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22485767/