UWP:来自Assets文件夹中文件的File.ReadAllBytes

时间:2016-03-16 11:27:59

标签: windows-mobile win-universal-app assets filepath

如何使用File.ReadAllBytes()Assets文件夹中的文件读入byte[]?因此我需要一个文件路径。我尝试使用ms-appx-web:///Assets/test.jpg,但这并没有奏效。 File.Exists()返回false。

如何获取资产文件夹的绝对路径?

1 个答案:

答案 0 :(得分:10)

这个片段应该做,

string fname = @"Assets\test.jpg";
StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await InstallationFolder.GetFileAsync(fname);
if(File.Exists(file.Path))
{
    var contents = File.ReadAllBytes(file.Path);
}