FileSystem.Print(Int32, Object[]) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将已设置显示格式的数据写入顺序文件。
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.IOException:FileNumber 不存在。
示例
此示例使用 Print 和 PrintLine 函数将数据写入文件。
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.
注解
Print提供的 和 PrintLine 函数是为了向后兼容,可能会影响性能。 对于非旧应用程序,对象 My.Computer.FileSystem 提供更好的性能。 有关详细信息,请参阅 Visual Basic 中的文件访问。
Print 不包括行末尾的换行符;但是, PrintLine 确实包含换行符。
使用 Print 写入的数据通常通过使用 LineInput 或 Input从文件中读取。
如果省略 Output 了 , PrintLine则会将空白行输出到文件中;对于 Print,不输出任何内容。 用逗号分隔的多个表达式将在选项卡边界上对齐,但逗号混合 TAB 可能会导致结果不一致。
对于 Boolean 数据, True 打印 或 False 。
True无论区域设置如何,都不会转换 和 False 关键字。
使用系统识别的标准短日期格式将日期数据写入文件。 当日期或时间组件缺失或零时,只会将所提供的部分写入文件。
如果 Output 数据为空,则不会向文件写入任何内容。 但是,如果 Output 列表数据为 DBNull, Null 则会写入 文件。
对于 Error 数据,输出显示为 Error errorcode。
Error 无论区域设置如何,都不会翻译关键字 (keyword) 。
使用 Print 写入文件的所有数据都是国际感知的;也就是说,使用适当的小数分隔符正确设置数据格式。 如果用户希望输出数据供多个区域设置使用, Write 则应使用 。
使用 Print 或 PrintLine 函数写入文件需要 Write 从 枚举访问 FileIOPermissionAccess 。 有关更多信息,请参见FileIOPermissionAccess。