写入一些文本到文件, 然后从文件读取回内存(方法二)

写入一些文本到文件, 然后从文件读取回内存(方法二)
; 示例: 这是个可运行脚本, 它写入一些文本到文件, 然后从文件读取回内存.
; 它提供了与 此 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%

 

给TA捐赠
共{{data.count}}人
人已捐赠
其他

复制文件夹

2018-1-3 9:07:52

其他

计算文件夹的大小, 包括其所有子文件夹中的文件

2018-1-3 9:27:42

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索