Lua file I/O operations

Source: Internet
Author: User

1.

Io. Open (filename [, mode])

Function: open a file in the specified mode. If the file is successfully opened, the file handle is returned. If the file fails, the NIL + error message is returned.

Mode:

"R": Read mode (default );

"W": Write mode;

"A": Add mode;

2.

File: Write (...)

Function: output the file content in the specified parameter format. The parameter must be a character or number. to output other values, use tostring or string. Format for conversion.

3.

File: Close ()

Function: Close the file. I am too lazy to 'safely Delete the hardware' when I pull a USB flash drive. the same is true for this command. Lua automatically recycles garbage ........

 

Routine:

 1 File = Io. Open ( "  A.txt " , "  W  "  )  2   --  Open a.txt with 'write mode ', and create a file if it does not exist.  3   4   File: Write ( "  Hello world.  "  )  5   -- Write a string to a file  6   7   File: Close  ()  8   --[[  Close files,  9   I almost never write close  10   In order not to mislead you, have you written down close?  11   Does it mean that I am a good teacher?  12   ] 

 

 

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.