Lua read-Write file code sample _lua

Source: Internet
Author: User
Tags assert lua

mode of reading and writing files:

Copy Code code as follows:

R-Read mode W-write mode (overwrite existing content)
A-attach mode (after existing content is attached)
B-Binary mode
r+-Read update mode (existing data retention)
w+-Write update mode (existing data erasure)
A +-Additional update mode (existing data retention, only appended to the end of the file)

 ' do--read data from File function ReadFile () Local filehandle = assert (Io.op 
    En ("test.txt", "R"), "not the file"); 
      If FileHandle then local outdata = Filehandle:read ("*all"); 
    Print (Outdata); 
    else print ("false"); 
  End Filehandle:close (errorinfo); End--write data to the file function WriteFile (databuffer) Local writehandle = assert (Io.open ("Write.txt", " 
 
    A + ")," not the file "); 
      If Writehandle then Writehandle:write (DataBuffer); 
    Print ("true"); 
    else print ("false"); 
  End Writehandle:close (); 
 
  End local Inputdata = 0; Repeat Inputdata = Io.read (); 
  --write the data from IO WriteFile (inputdata); Until Inputdata = = ' # ' End 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.