积极答复者
读取文件的 api 是什么,对于 javascript 的 metro app 来说。

问题
答案
-
您好,
在Metro Style环境里,StorageFile 代表一个文件。你可以调用静态方法 StorageFile.GetFileFromPathAsync 或 StorageFile.GetFileFromApplicationUriAsync,获取一个StorageFile对象,再作相应的文件操作。
通过调用 FileIO 类的 ReadTextAsync 方法,你可以读取本地文件。
请参阅 File Access Sample。
Best wishes,
Robin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Hello Don Li 2012年3月6日 8:58
- 已标记为答案 _bug_ 2012年3月7日 11:03
全部回复
-
您好,
在Metro Style环境里,StorageFile 代表一个文件。你可以调用静态方法 StorageFile.GetFileFromPathAsync 或 StorageFile.GetFileFromApplicationUriAsync,获取一个StorageFile对象,再作相应的文件操作。
通过调用 FileIO 类的 ReadTextAsync 方法,你可以读取本地文件。
请参阅 File Access Sample。
Best wishes,
Robin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Hello Don Li 2012年3月6日 8:58
- 已标记为答案 _bug_ 2012年3月7日 11:03
-
你好, getFileOperation總是失敗, 請問哪裡出了錯, 謝謝
原始碼如下:
void App::OnFileActivated(Windows::ApplicationModel::Activation::FileActivatedEventArgs^ args)
{String^ path = args->Files->GetAt(0)->Path;
task<StorageFile^> getFileOperation(StorageFile::GetFileFromPathAsync(path));
getFileOperation.then([this](StorageFile^ file)
{
return FileIO::ReadTextAsync(file);
});}