Difference between revisions of "love.filesystem.newFile (简体中文)"

(Created page with "新建一个 File 对象。 文件在存取前必须先被打开 == 函数 == === 概要 === <source lang="lua"> file = love.filesystem.newFile( filename ) </source> ===...")
 
m (另见)
 
(2 intermediate revisions by the same user not shown)
Line 21: Line 21:
 
file, errorstr = love.filesystem.newFile( filename, mode )
 
file, errorstr = love.filesystem.newFile( filename, mode )
 
</source>
 
</source>
=== Arguments ===
+
=== 参数 ===
 
{{param|string|filename|The filename of the file.}}
 
{{param|string|filename|The filename of the file.}}
 
{{param|FileMode|mode|The mode to open the file in.}}
 
{{param|FileMode|mode|The mode to open the file in.}}
=== Returns ===
+
=== 返回值 ===
 
{{param|File|file|The new File object, or nil if an error occurred.}}
 
{{param|File|file|The new File object, or nil if an error occurred.}}
 
{{param|string|errorstr|The error string if an error occurred.}}
 
{{param|string|errorstr|The error string if an error occurred.}}
  
 
== 例 ==
 
== 例 ==
=== Open a file and read everything ===
+
=== 打开一个文件并读取所有东西 ===
 
<source lang="lua">
 
<source lang="lua">
 
file = love.filesystem.newFile("data.txt")
 
file = love.filesystem.newFile("data.txt")
Line 37: Line 37:
 
-- use the data ...
 
-- use the data ...
 
</source>
 
</source>
 +
 
== 另见 ==
 
== 另见 ==
 
* [[parent::love.filesystem (简体中文)]]
 
* [[parent::love.filesystem (简体中文)]]
* [[Constructs::File]]
+
* [[Constructs::File (简体中文)]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Creates a new [[File]] object.}}
 
{{#set:Description=Creates a new [[File]] object.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.filesystem.newFile}}
 
{{i18n|love.filesystem.newFile}}

Latest revision as of 13:35, 23 October 2019

新建一个 File 对象。 文件在存取前必须先被打开

函数

概要

file = love.filesystem.newFile( filename )

参数

string filename
The filename of the file.

返回值

File file
The new File object.

注意

Please note that this function will not return any error message (e.g. if you use an invalid filename) because it just creates the File Object. You can still check if the file is valid by using File:open which returns a boolean and an error message if something goes wrong while opening the file.

函数

Available since LÖVE 0.9.0
This variant is not supported in earlier versions.

Creates a File object and opens it for reading, writing, or appending.

概要

file, errorstr = love.filesystem.newFile( filename, mode )

参数

string filename
The filename of the file.
FileMode mode
The mode to open the file in.

返回值

File file
The new File object, or nil if an error occurred.
string errorstr
The error string if an error occurred.

打开一个文件并读取所有东西

file = love.filesystem.newFile("data.txt")
file:open("r")
data = file:read()
file:close()
-- use the data ...

另见


Other Languages