写入一些文本到文件, 然后从文件读取回内存(方法二)
; 示例: 这是个可运行脚本, 它写入一些文本到文件, 然后从文件读取回内存.
; 它提供了与 此 DllCall 示例 同样的功能.
FileSelectFile, FileName, S16,, Create a new file:
if (FileName = "")
return
file := FileOpen(FileName, "w")
if !IsObject(file)
{
MsgBox Can't open "%FileName%" for writing.
return
}
TestString := "This is a test string.`r`n" ; 通过这种方式写入内容到文件时, 要使用 `r`n 而不是 `n 来开始新行.
file.Write(TestString)
file.Close()
; 现在已经把内容写入文件了, 重新把它们读取回内存中.
file := FileOpen(FileName, "r-d") ; 读取文件 ("r"), 共享除删除 ("-d") 外的所有访问权限
if !IsObject(file)
{
MsgBox Can't open "%FileName%" for reading.
return
}
CharsToRead := StrLen(TestString)
TestString := file.Read(CharsToRead)
file.Close()
MsgBox The following string was read from the file: %TestString%
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

