在此問題中其他用戶提出了一些重要論點:How to write to a text file inside of the application後,我決定不使用資源文件,而是在文件夾中創建一個文件&然後從/那裏。程序無法寫入新建的文本文件
雖然由於某種原因,我似乎無法寫入有問題的文件,但它一直拋出異常,告訴我該文件已被另一進程使用。
下面是我用於寫入此文件的代碼。
If System.IO.File.Exists(credentials) Then
Dim objWriter As New System.IO.StreamWriter(credentials, False)
objWriter.WriteLine(remember)
objWriter.Close()
Else
System.IO.Directory.CreateDirectory(Mid(My.Application.Info.DirectoryPath, 1, 1) & ":\ProgramData\DayZAdminPanel")
System.IO.File.Create(credentials)
Dim objWriter As New System.IO.StreamWriter(credentials, False)
objWriter.WriteLine(remember)
objWriter.Close()
End If
關於如何寫入有問題的文本文件的任何想法?
謝謝,這是有效的,但我更喜歡將文件保存在我的問題中使用的目錄中。 – Yorrick 2013-03-18 22:42:00
Enum'SpecialFolder.CommonApplicationData'在Win7中解析爲C:\ PROGRAMDATA,在C:\ DOCUMENTS&SETTINGS \ ALLUSER ...中爲XP。所以,這是獨立於底層操作系統的方式。 – Steve 2013-03-18 22:44:40
哦,我看到了,我認爲'SpecialFolder.CommmonApplicationData'是%appdata%區域中位置的參考。我的壞 – Yorrick 2013-03-18 23:08:52