Difference between revisions of "(File):write"

m (Add information about returned error message.)
m (Windows 10 1809 Notepad now treats LF)
 
Line 26: Line 26:
  
 
== Notes ==
 
== Notes ==
'''Writing to multiple lines''': In Windows, some text editors (e.g. Notepad) only treat CRLF ("\r\n") as a new line.
+
'''Writing to multiple lines''': In Windows, some text editors (e.g. Notepad before Windows 10 1809) only treat CRLF ("\r\n") as a new line.
 
<source lang="lua">
 
<source lang="lua">
 
--example
 
--example

Latest revision as of 03:25, 13 October 2018

Write data to a file.

Function

Synopsis

success, err = File:write( data, size )

Arguments

string data
The string data to write.
number size (all)
How many bytes to write.

Returns

boolean success
Whether the operation was successful.
string err
The error string if an error occurred.

Function

Synopsis

success, err = File:write( data, size )

Arguments

Data data
The Data object to write.
number size (all)
How many bytes to write.

Returns

boolean success
Whether the operation was successful.
string errorstr
The error string if an error occurred.

Notes

Writing to multiple lines: In Windows, some text editors (e.g. Notepad before Windows 10 1809) only treat CRLF ("\r\n") as a new line.

--example
f = love.filesystem.newFile("note.txt")
f:open("w")
for i = 1, 10 do
    f:write("This is line "..i.."!\r\n")
end
f:close()

See Also


Other Languages