💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~lua|woo print('文件流读取测试:') local lfs = woo.lfs local mode = 'RO' print('===文件model描述-> A:append(追加),RW:readWrite(读写),RO:readOnly(只读),WO:writeOnly(只写),C:create(不存在则创建文件)===') print('创建测试文件test.txt,进行移动读写测试:') local e = lfs.with('test.txt', function(f) -- lfs不是类,直接用.即可调用内部方法 print('开始写入测试文本') f.write("hello world!\r\nline2\nline3") f.seek(0, "S") print('写入测试文本完毕,文件读写指针在文件末,需要用seek移动到首,才能继续读文件') _foreach(true, function(p) -- 每次读取10字节,可以使用:readline() 每次读取一行 local l, bts, err = f.read(10) print('read ok',l) if l < 1 then -- 读取到文件尾部则返回true 跳出循环即可 --print(err) return true end local s = _strs(bts) print(s) end) end, mode) print('错误信息:', e) ~~~