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

tes*_*ing 7 assets windows-mobile filepath win-universal-app

如何使用File.ReadAllBytes()Assets文件夹中读取文件到byte[]?因此我需要一个文件路径.我试过了ms-appx-web:///Assets/test.jpg,但那没用.File.Exists()返回false.

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

Sou*_*jan 12

这个片段应该做,

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);
}
Run Code Online (Sandbox Code Playgroud)