如何使用File.ReadAllBytes()
将Assets
文件夹中的文件读入byte[]
?因此我需要一个文件路径。我尝试使用ms-appx-web:///Assets/test.jpg
,但这并没有奏效。 File.Exists()
返回false。
如何获取资产文件夹的绝对路径?
答案 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);
}