WriteAllText方法可用來附加至文本檔,條件是將append參數設定為True。
若要附加至文本檔
WriteAllText使用 方法,指定要附加的目標檔案和字串,並將 參數設定append為True。這個範例會將字串
"This is a test string."寫入名為Testfile.txt的檔案。Dim inputString As String = "This is a test string." My.Computer.FileSystem.WriteAllText( "C://testfile.txt", inputString, True)
健全的程式設計
以下條件可能會造成例外狀況:
路徑無效,原因如下:它是長度為零的字串、只包含空格符、包含無效字元,或是裝置路徑 (開頭為 \\.\) (ArgumentException)。
路徑是無效的,因為它是
Nothing(ArgumentNullException)。File指向不存在的路徑(FileNotFoundException 或 DirectoryNotFoundException)。檔案正由另一個進程使用,或發生 I/O 錯誤 (IOException)。
路徑超過系統定義的最大長度 (PathTooLongException)。
路徑中的檔案或目錄名稱包含冒號(:)或格式無效 (NotSupportedException)。
使用者缺少檢視路徑的必要許可權(SecurityException)。