我試圖寫入我的項目文件夾中的txt文件,但我不能拋出異常,因爲某些原因,我嘗試過所有的東西,但它仍然不會工作無法寫入文本文件
// settings
// same as (ms-appx:///MyFolder/MyFile.txt)
var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
_Folder = await _Folder.GetFolderAsync("MyFolder");
// acquire file
var _File = await _Folder.GetFileAsync("MyFile.txt");
Assert.IsNotNull(_File, "Acquire File");
// write content
var _WriteThis = "Hello World";
// Error here
await Windows.Storage.FileIO.WriteTextAsync(_File, _WriteThis);
這裏是我來我就一直使用錯誤發生時,我想寫入文件
下面的代碼是例外
System.UnauthorizedAccessException was unhandled
HResult=-2147024891
Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ManipulatingTxtFiles.MainPage.<addBtn_Click>d__a.MoveNext() in c:\Users\Tunde\Documents\Visual Studio 2012\Projects\ManipulatingTxtFiles\ManipulatingTxtFiles\MainPage.xaml.cs:line 115
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.WinRTSynchronizationContext.Invoker.<InvokeCore>b__0(Object o)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
InnerException:
你能發佈異常消息和堆棧跟蹤嗎? –
它已被添加 – user3063540
爲什麼不直接使用[StreamWriter](http://msdn.microsoft.com/en-us/library/vstudio/system.io.streamwriter)對象? – Brandon