ReadFile()

语法

Result = ReadFile(#File, Filename$ [, Flags])
概要
Open an existing file for read-only operations.

参数

#File The number to identify the file. #PB_Any can be used to auto-generate this number.
Filename$ The filename and path to the file. If the filename does not include a full path, it is interpreted relative to the current directory.
Flags (optional) It can be a combination (using the '| operand) of the following values:
  #PB_File_SharedRead : the opened file can be read by another process (Windows only).
  #PB_File_NoBuffering: the internal PureBasic file buffering system will be disabled for this file. 
                        FileBuffersSize() can not be used on this file.

返回值

Returns nonzero if the file was opened successfully and zero if there was an error. If #PB_Any was used as the #File parameter then the new generated number is returned on success.

Remarks

To open a file for reading and writing, use the OpenFile() function. To create a new and empty file, use the CreateFile() function.

示例


  If ReadFile(0, "Text.txt")   ; if the file could be read, we continue...
    While Eof(0) = 0           ; loop as long the 'end of file' isn't reached
      Debug ReadString(0)      ; display line by line in the debug window
    Wend
    CloseFile(0)               ; close the previously opened file
  Else
    MessageRequester("Information","Couldn't open the file!")
  EndIf

参阅

OpenFile(), CreateFile(), CloseFile()

已支持操作系统

所有

<- ReadDouble() - File Index - ReadFloat() ->