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

定義

將顯示格式資料寫入循序檔。

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

參數

FileNumber
Int32

必要。 任何有效的檔案數目。

Output
Object[]

選擇性。 要寫入檔案的零或多個逗點分隔運算式。

Output 引數設定為︰

T:System.IO.IOException︰檔案模式無效。

T:System.IO.IOExceptionFileNumber 不存在。

範例

此範例會使用 PrintPrintLine 函式將數據寫入檔案。

FileOpen(1, "c:\trash.txt", OpenMode.Output)   ' Open file for output.
Print(1, "This is a test.")   ' Print text to file.
PrintLine(1)   ' Print blank line to file.
PrintLine(1, "Zone 1", TAB(), "Zone 2")   ' Print in two print zones.
PrintLine(1, "Hello", "World")   ' Separate strings with a tab.
PrintLine(1, SPC(5), "5 leading spaces ")   ' Print five leading spaces.
PrintLine(1, TAB(10), "Hello")   ' Print word at column 10.

' Assign Boolean, Date, and Error 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.
PrintLine(1, aBool, " is a Boolean value")
PrintLine(1, aDate, " is a date")
FileClose(1)   ' Close file.

備註

PrintLinePrint式是針對回溯相容性而提供,而且可能會影響效能。 對於非舊版應用程式, My.Computer.FileSystem 物件可提供更佳的效能。 如需詳細資訊,請參閱 Visual Basic 的檔案存取

Print 不包含行尾端的換行字元;不過, PrintLine 會包含換行字元。

使用 Print 寫入的數據通常會使用 LineInputInput從檔案讀取。

如果您省略 OutputPrintLine則會將空白行列印至檔案;若 Print為 ,則不會輸出任何內容。 以逗號分隔的多個表達式會在索引標籤界限上對齊,但混用逗號,而且 TAB 可能會導致不一致的結果。

如果是 Boolean 資料,則會 True 列印 或 False 。 不論 True 地區設定為何,都不會轉譯 和 False 關鍵詞。

日期數據會使用系統所辨識的標準簡短日期格式寫入檔案。 當日期或時間元件遺失或零時,只會將提供的元件寫入檔案。

如果 Output 數據是空的,則不會寫入檔案。 不過,如果 Output 清單數據是 DBNullNull 則會寫入檔案。

針對 Error 資料,輸出會顯示為 Error errorcodeError不論地區設定為何,關鍵詞都不會轉譯。

使用 Print 寫入檔案的所有數據都是國際感知的;也就是說,數據會使用適當的小數分隔符正確格式化。 如果使用者要輸出資料供多個地區設定使用, Write 則應該使用 。

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

適用於

另請參閱