Windows phone 8.1 使用StreamResourceInfo GetResourceStream(Uri uriResource)读取文件
我想使用StreamResourceInfoWindows phone 8.1 使用StreamResourceInfo GetResourceStream(Uri uriResource)读取文件,windows-phone-8.1,Windows Phone 8.1,我想使用StreamResourceInfoGetResourceStream(Uri-uriResource)方法读取文件,其中我的文件名是Assets,其类型是if-file(扩展名),因此我在windows phone 8.1 sdk中使用了以下代码行: StreamResourceInfo info = App.GetResourceStream(new Uri("Assets", UriKind.Relative)); 但是info变量显示空值。在您的情况下是否需要使用GetReso
GetResourceStream(Uri-uriResource)
方法读取文件,其中我的文件名是Assets,其类型是if-file(扩展名),因此我在windows phone 8.1 sdk中使用了以下代码行:
StreamResourceInfo info = App.GetResourceStream(new Uri("Assets", UriKind.Relative));
但是info变量显示空值。在您的情况下是否需要使用
GetResourceStream
?您的问题有点不清楚,但如果您想获取文件的内容,可以尝试以下方法:
public async Task<string> GetFileContent(string fileName)
{
try
{
string text = string.Empty;
StorageFile storageFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileName);
if (storageFile != null)
{
IBuffer buffer = await FileIO.ReadBufferAsync(storageFile);
DataReader reader = DataReader.FromBuffer(buffer);
byte[] fileContent = new byte[reader.UnconsumedBufferLength];
reader.ReadBytes(fileContent);
text = Encoding.UTF8.GetString(fileContent, 0, fileContent.Length);
}
return text;
}
catch (Exception e)
{
return string.Empty;
}
}
var fileContent = await GetFileContent(@"Assets\[yourfile]");