讀取打開的文本文件中指定數(shù)量的字符.
FileRead ( "文件句柄/文件名" [, 數(shù)量] )
文件句柄/文件名 | 由此前 FileOpen 函數(shù)返回的文件句柄. 也可以使用文件名字符串作為參數(shù). |
數(shù)量 | [可選參數(shù)] 讀取的字符數(shù). 見備注. |
成功: | 返回讀取的字符/二進制數(shù)據(jù). @extended 返回讀取的字節(jié)/字符數(shù)量. |
專用: | 設(shè)置 @error 為 -1, 已讀到文件尾. |
失敗: | 設(shè)置 @error 為 1, 文件以非讀模式打開, 或其它錯誤. |
Local $file
= FileOpen("test.txt", 0)
; 檢查以只讀打開的文件
If $file
= -1 Then
MsgBox(0, "錯誤", "無法打開文件.")
Exit
EndIf
;
每次讀取一個字符,直到文件結(jié)束(EOF)(譯注:讀中文必須設(shè)置為遠大于1的值!)(譯注的譯注(thesnow):ANSI編碼中,一個中文為兩個字符/字節(jié))
While 1
Local
$chars =
FileRead($file,
1)
If
@error =
-1 Then ExitLoop
MsgBox(0, "讀取的字符:
", $chars)
Wend
FileClose($file)
provider with jb51.net (unicode) |