FileSystem.WriteLine(Int32, Object[]) 方法

定義

將資料寫入序列檔案。 以 寫入 Write 的資料通常會從 Input檔案中讀取。

public:
 static void WriteLine(int FileNumber, ... cli::array <System::Object ^> ^ Output);
public static void WriteLine(int FileNumber, params object[] Output);
static member WriteLine : int * obj[] -> unit
Public Sub WriteLine (FileNumber As Integer, ParamArray Output As Object())

參數

FileNumber
Int32

必須的。 一個 Integer 包含任意有效檔案號的表達式。

Output
Object[]

Optional. 一個或多個逗號分隔的表達式,用來寫入檔案。

範例

這個範例使用 Write 了將原始資料寫入序列檔案的函式。

' Open file for output.
FileOpen(1, "TestFile.txt", OpenMode.Output)
' Print text to the file. The quotation marks will be in the display.
Write(1, "This is a test.")
' Go to the next line.
WriteLine(1)
' Skip a line.
WriteLine(1)
' Print in two print zones. You will see commas and quotation marks
' in the output file.
WriteLine(1, "Zone 1", SPC(10), "Zone 2")
' Build a longer string before calling WriteLine.
WriteLine(1, "Hello" & "  " & "World")
' Include five leading spaces.
WriteLine(1, SPC(5), "Leading spaces")
' Print a word starting at column 10.
WriteLine(1, TAB(10), "Hello")

' Assign Boolean and Date values.
Dim aBool As Boolean
Dim aDate As DateTime
aBool = False
aDate = DateTime.Parse("February 12, 1969")

' Dates and Booleans are translated using locale settings of 
' your system.
WriteLine(1, aBool & " is a Boolean value.")
WriteLine(1, aDate & " is a date.")
' Close the file.
FileClose(1)

' Contents of TestFile.txt
'"This is a test.",
'
'"Zone 1",          "Zone 2"
'"Hello  World"
'     "Leading spaces"
'         ,"Hello"
'"False is a Boolean value."
'"2/12/1969 is a date."

備註

WriteWriteLine 函式是為了向下相容而提供,可能會影響效能。 對於非傳統應用程式,物件 My.Computer.FileSystem 提供更好的效能。 欲了解更多資訊,請參閱檔案存取Visual Basic

如果你省略 Output了 ,檔案會印出一行空白。 多個表達式可以用逗號分隔。

與函 Print 式不同,函 Write 式會在寫入檔案時在項目間加上逗號,並在字串周圍加上引號。 你不必在清單中加入明確的分隔符。 當 Write 用於寫入檔案資料時,僅支援數字、 Boolean日期、空值及 Error 資料格式。 遵循以下普遍假設,以確保資料無論地點為何,都能以 讀取並正確解讀 Input

  • 數值資料總是以週期作為十進位分隔符來寫入。

  • 資料Boolean則會印出或#FALSE##TRUE#True無論在哪裡,關鍵字False和關鍵字都不會被翻譯。

  • 日期資料會以通用日期格式寫入檔案。 當日期或時間成分缺失或為零時,僅寫入所提供的部分。

  • 如果 Output 資料是空的,檔案不會寫入任何東西。 然而,對於空資料, 是 #NULL# 寫入的。

  • 對於 Error 資料,輸出為 #ERROR errorcode#。 無論在哪裡,關鍵字 Error 都不會被翻譯。

WriteLine在寫入最後一個字元Output到檔案後,插入一個換行字元(即回車/換行,或 Chr(13) + Chr(10))。

你可以用雙引號或「」來嵌入字串中的引號。 例如,

Dim x As String = "Double quotation marks aren't ""difficult"" to handle."

回傳一個值為 的 Double quotation marks aren't "difficult" to handle字串。

使用 or WriteWriteLine 函式寫入檔案需要 Append 從列舉中 FileIOPermissionAccess 存取。 如需詳細資訊,請參閱FileIOPermissionAccess

適用於

另請參閱