class_file.rst 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the File.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_File:
  6. File
  7. ====
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Type to handle file reading and writing operations.
  13. Properties
  14. ----------
  15. +-------------------------+-----------------------------------------------------+-------+
  16. | :ref:`bool<class_bool>` | :ref:`endian_swap<class_File_property_endian_swap>` | false |
  17. +-------------------------+-----------------------------------------------------+-------+
  18. Methods
  19. -------
  20. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`close<class_File_method_close>` **(** **)** |
  22. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`bool<class_bool>` | :ref:`eof_reached<class_File_method_eof_reached>` **(** **)** const |
  24. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | :ref:`file_exists<class_File_method_file_exists>` **(** :ref:`String<class_String>` path **)** const |
  26. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`int<class_int>` | :ref:`get_16<class_File_method_get_16>` **(** **)** const |
  28. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`get_32<class_File_method_get_32>` **(** **)** const |
  30. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_64<class_File_method_get_64>` **(** **)** const |
  32. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_8<class_File_method_get_8>` **(** **)** const |
  34. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`String<class_String>` | :ref:`get_as_text<class_File_method_get_as_text>` **(** **)** const |
  36. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_buffer<class_File_method_get_buffer>` **(** :ref:`int<class_int>` len **)** const |
  38. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_csv_line<class_File_method_get_csv_line>` **(** :ref:`String<class_String>` delim="," **)** const |
  40. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`get_double<class_File_method_get_double>` **(** **)** const |
  42. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_error<class_File_method_get_error>` **(** **)** const |
  44. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_float<class_File_method_get_float>` **(** **)** const |
  46. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`int<class_int>` | :ref:`get_len<class_File_method_get_len>` **(** **)** const |
  48. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`String<class_String>` | :ref:`get_line<class_File_method_get_line>` **(** **)** const |
  50. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`String<class_String>` | :ref:`get_md5<class_File_method_get_md5>` **(** :ref:`String<class_String>` path **)** const |
  52. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_modified_time<class_File_method_get_modified_time>` **(** :ref:`String<class_String>` file **)** const |
  54. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`String<class_String>` | :ref:`get_pascal_string<class_File_method_get_pascal_string>` **(** **)** |
  56. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`String<class_String>` | :ref:`get_path<class_File_method_get_path>` **(** **)** const |
  58. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`String<class_String>` | :ref:`get_path_absolute<class_File_method_get_path_absolute>` **(** **)** const |
  60. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`int<class_int>` | :ref:`get_position<class_File_method_get_position>` **(** **)** const |
  62. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`float<class_float>` | :ref:`get_real<class_File_method_get_real>` **(** **)** const |
  64. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`String<class_String>` | :ref:`get_sha256<class_File_method_get_sha256>` **(** :ref:`String<class_String>` path **)** const |
  66. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_File_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** const |
  68. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`bool<class_bool>` | :ref:`is_open<class_File_method_is_open>` **(** **)** const |
  70. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open<class_File_method_open>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` flags **)** |
  72. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_compressed<class_File_method_open_compressed>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`CompressionMode<enum_File_CompressionMode>` compression_mode=0 **)** |
  74. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_encrypted<class_File_method_open_encrypted>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`PoolByteArray<class_PoolByteArray>` key **)** |
  76. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_encrypted_with_pass<class_File_method_open_encrypted_with_pass>` **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`String<class_String>` pass **)** |
  78. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`seek<class_File_method_seek>` **(** :ref:`int<class_int>` position **)** |
  80. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`seek_end<class_File_method_seek_end>` **(** :ref:`int<class_int>` position=0 **)** |
  82. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`store_16<class_File_method_store_16>` **(** :ref:`int<class_int>` value **)** |
  84. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`store_32<class_File_method_store_32>` **(** :ref:`int<class_int>` value **)** |
  86. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`store_64<class_File_method_store_64>` **(** :ref:`int<class_int>` value **)** |
  88. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`store_8<class_File_method_store_8>` **(** :ref:`int<class_int>` value **)** |
  90. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`store_buffer<class_File_method_store_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  92. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`store_csv_line<class_File_method_store_csv_line>` **(** :ref:`PoolStringArray<class_PoolStringArray>` values, :ref:`String<class_String>` delim="," **)** |
  94. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | void | :ref:`store_double<class_File_method_store_double>` **(** :ref:`float<class_float>` value **)** |
  96. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | void | :ref:`store_float<class_File_method_store_float>` **(** :ref:`float<class_float>` value **)** |
  98. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | void | :ref:`store_line<class_File_method_store_line>` **(** :ref:`String<class_String>` line **)** |
  100. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | void | :ref:`store_pascal_string<class_File_method_store_pascal_string>` **(** :ref:`String<class_String>` string **)** |
  102. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | void | :ref:`store_real<class_File_method_store_real>` **(** :ref:`float<class_float>` value **)** |
  104. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | void | :ref:`store_string<class_File_method_store_string>` **(** :ref:`String<class_String>` string **)** |
  106. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | void | :ref:`store_var<class_File_method_store_var>` **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)** |
  108. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. Enumerations
  110. ------------
  111. .. _enum_File_ModeFlags:
  112. .. _class_File_constant_READ:
  113. .. _class_File_constant_WRITE:
  114. .. _class_File_constant_READ_WRITE:
  115. .. _class_File_constant_WRITE_READ:
  116. enum **ModeFlags**:
  117. - **READ** = **1** --- Opens the file for read operations.
  118. - **WRITE** = **2** --- Opens the file for write operations. Create it if the file does not exist and truncate if it exists.
  119. - **READ_WRITE** = **3** --- Opens the file for read and write operations. Does not truncate the file.
  120. - **WRITE_READ** = **7** --- Opens the file for read and write operations. Create it if the file does not exist and truncate if it exists.
  121. .. _enum_File_CompressionMode:
  122. .. _class_File_constant_COMPRESSION_FASTLZ:
  123. .. _class_File_constant_COMPRESSION_DEFLATE:
  124. .. _class_File_constant_COMPRESSION_ZSTD:
  125. .. _class_File_constant_COMPRESSION_GZIP:
  126. enum **CompressionMode**:
  127. - **COMPRESSION_FASTLZ** = **0** --- Uses the `FastLZ <http://fastlz.org/>`_ compression method.
  128. - **COMPRESSION_DEFLATE** = **1** --- Uses the `DEFLATE <https://en.wikipedia.org/wiki/DEFLATE>`_ compression method.
  129. - **COMPRESSION_ZSTD** = **2** --- Uses the `Zstandard <https://facebook.github.io/zstd/>`_ compression method.
  130. - **COMPRESSION_GZIP** = **3** --- Uses the `gzip <https://www.gzip.org/>`_ compression method.
  131. Description
  132. -----------
  133. File type. This is used to permanently store data into the user device's file system and to read from it. This can be used to store game save data or player configuration files, for example.
  134. Here's a sample on how to write and read from a file:
  135. ::
  136. func save(content):
  137. var file = File.new()
  138. file.open("user://save_game.dat", File.WRITE)
  139. file.store_string(content)
  140. file.close()
  141. func load():
  142. var file = File.new()
  143. file.open("user://save_game.dat", File.READ)
  144. var content = file.get_as_text()
  145. file.close()
  146. return content
  147. Tutorials
  148. ---------
  149. - :doc:`../getting_started/step_by_step/filesystem`
  150. Property Descriptions
  151. ---------------------
  152. .. _class_File_property_endian_swap:
  153. - :ref:`bool<class_bool>` **endian_swap**
  154. +-----------+------------------------+
  155. | *Default* | false |
  156. +-----------+------------------------+
  157. | *Setter* | set_endian_swap(value) |
  158. +-----------+------------------------+
  159. | *Getter* | get_endian_swap() |
  160. +-----------+------------------------+
  161. If ``true``, the file's endianness is swapped. Use this if you're dealing with files written on big-endian machines.
  162. **Note:** This is about the file format, not CPU type. This is always reset to ``false`` whenever you open the file.
  163. Method Descriptions
  164. -------------------
  165. .. _class_File_method_close:
  166. - void **close** **(** **)**
  167. Closes the currently opened file.
  168. .. _class_File_method_eof_reached:
  169. - :ref:`bool<class_bool>` **eof_reached** **(** **)** const
  170. Returns ``true`` if the file cursor has read past the end of the file.
  171. **Note:** This function will still return ``false`` while at the end of the file and only activates when reading past it. This can be confusing but it conforms to how low-level file access works in all operating systems. There is always :ref:`get_len<class_File_method_get_len>` and :ref:`get_position<class_File_method_get_position>` to implement a custom logic.
  172. .. _class_File_method_file_exists:
  173. - :ref:`bool<class_bool>` **file_exists** **(** :ref:`String<class_String>` path **)** const
  174. Returns ``true`` if the file exists in the given path.
  175. **Note:** Many resources types are imported (e.g. textures or sound files), and that their source asset will not be included in the exported game, as only the imported version is used (in the ``res://.import`` folder). To check for the existence of such resources while taking into account the remapping to their imported location, use :ref:`ResourceLoader.exists<class_ResourceLoader_method_exists>`. Typically, using ``File.file_exists`` on an imported resource would work while you are developing in the editor (the source asset is present in ``res://``, but fail when exported).
  176. .. _class_File_method_get_16:
  177. - :ref:`int<class_int>` **get_16** **(** **)** const
  178. Returns the next 16 bits from the file as an integer.
  179. .. _class_File_method_get_32:
  180. - :ref:`int<class_int>` **get_32** **(** **)** const
  181. Returns the next 32 bits from the file as an integer.
  182. .. _class_File_method_get_64:
  183. - :ref:`int<class_int>` **get_64** **(** **)** const
  184. Returns the next 64 bits from the file as an integer.
  185. .. _class_File_method_get_8:
  186. - :ref:`int<class_int>` **get_8** **(** **)** const
  187. Returns the next 8 bits from the file as an integer.
  188. .. _class_File_method_get_as_text:
  189. - :ref:`String<class_String>` **get_as_text** **(** **)** const
  190. Returns the whole file as a :ref:`String<class_String>`.
  191. Text is interpreted as being UTF-8 encoded.
  192. .. _class_File_method_get_buffer:
  193. - :ref:`PoolByteArray<class_PoolByteArray>` **get_buffer** **(** :ref:`int<class_int>` len **)** const
  194. Returns next ``len`` bytes of the file as a :ref:`PoolByteArray<class_PoolByteArray>`.
  195. .. _class_File_method_get_csv_line:
  196. - :ref:`PoolStringArray<class_PoolStringArray>` **get_csv_line** **(** :ref:`String<class_String>` delim="," **)** const
  197. Returns the next value of the file in CSV (Comma-Separated Values) format. You can pass a different delimiter ``delim`` to use other than the default ``","`` (comma). This delimiter must be one-character long.
  198. Text is interpreted as being UTF-8 encoded.
  199. .. _class_File_method_get_double:
  200. - :ref:`float<class_float>` **get_double** **(** **)** const
  201. Returns the next 64 bits from the file as a floating-point number.
  202. .. _class_File_method_get_error:
  203. - :ref:`Error<enum_@GlobalScope_Error>` **get_error** **(** **)** const
  204. Returns the last error that happened when trying to perform operations. Compare with the ``ERR_FILE_*`` constants from :ref:`Error<enum_@GlobalScope_Error>`.
  205. .. _class_File_method_get_float:
  206. - :ref:`float<class_float>` **get_float** **(** **)** const
  207. Returns the next 32 bits from the file as a floating-point number.
  208. .. _class_File_method_get_len:
  209. - :ref:`int<class_int>` **get_len** **(** **)** const
  210. Returns the size of the file in bytes.
  211. .. _class_File_method_get_line:
  212. - :ref:`String<class_String>` **get_line** **(** **)** const
  213. Returns the next line of the file as a :ref:`String<class_String>`.
  214. Text is interpreted as being UTF-8 encoded.
  215. .. _class_File_method_get_md5:
  216. - :ref:`String<class_String>` **get_md5** **(** :ref:`String<class_String>` path **)** const
  217. Returns an MD5 String representing the file at the given path or an empty :ref:`String<class_String>` on failure.
  218. .. _class_File_method_get_modified_time:
  219. - :ref:`int<class_int>` **get_modified_time** **(** :ref:`String<class_String>` file **)** const
  220. Returns the last time the ``file`` was modified in unix timestamp format or returns a :ref:`String<class_String>` "ERROR IN ``file``". This unix timestamp can be converted to datetime by using :ref:`OS.get_datetime_from_unix_time<class_OS_method_get_datetime_from_unix_time>`.
  221. .. _class_File_method_get_pascal_string:
  222. - :ref:`String<class_String>` **get_pascal_string** **(** **)**
  223. Returns a :ref:`String<class_String>` saved in Pascal format from the file.
  224. Text is interpreted as being UTF-8 encoded.
  225. .. _class_File_method_get_path:
  226. - :ref:`String<class_String>` **get_path** **(** **)** const
  227. Returns the path as a :ref:`String<class_String>` for the current open file.
  228. .. _class_File_method_get_path_absolute:
  229. - :ref:`String<class_String>` **get_path_absolute** **(** **)** const
  230. Returns the absolute path as a :ref:`String<class_String>` for the current open file.
  231. .. _class_File_method_get_position:
  232. - :ref:`int<class_int>` **get_position** **(** **)** const
  233. Returns the file cursor's position.
  234. .. _class_File_method_get_real:
  235. - :ref:`float<class_float>` **get_real** **(** **)** const
  236. Returns the next bits from the file as a floating-point number.
  237. .. _class_File_method_get_sha256:
  238. - :ref:`String<class_String>` **get_sha256** **(** :ref:`String<class_String>` path **)** const
  239. Returns a SHA-256 :ref:`String<class_String>` representing the file at the given path or an empty :ref:`String<class_String>` on failure.
  240. .. _class_File_method_get_var:
  241. - :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)** const
  242. Returns the next :ref:`Variant<class_Variant>` value from the file. If ``allow_objects`` is ``true``, decoding objects is allowed.
  243. **Warning:** Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution.
  244. .. _class_File_method_is_open:
  245. - :ref:`bool<class_bool>` **is_open** **(** **)** const
  246. Returns ``true`` if the file is currently opened.
  247. .. _class_File_method_open:
  248. - :ref:`Error<enum_@GlobalScope_Error>` **open** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` flags **)**
  249. Opens the file for writing or reading, depending on the flags.
  250. .. _class_File_method_open_compressed:
  251. - :ref:`Error<enum_@GlobalScope_Error>` **open_compressed** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`CompressionMode<enum_File_CompressionMode>` compression_mode=0 **)**
  252. Opens a compressed file for reading or writing.
  253. .. _class_File_method_open_encrypted:
  254. - :ref:`Error<enum_@GlobalScope_Error>` **open_encrypted** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`PoolByteArray<class_PoolByteArray>` key **)**
  255. Opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it.
  256. .. _class_File_method_open_encrypted_with_pass:
  257. - :ref:`Error<enum_@GlobalScope_Error>` **open_encrypted_with_pass** **(** :ref:`String<class_String>` path, :ref:`ModeFlags<enum_File_ModeFlags>` mode_flags, :ref:`String<class_String>` pass **)**
  258. Opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it.
  259. .. _class_File_method_seek:
  260. - void **seek** **(** :ref:`int<class_int>` position **)**
  261. Changes the file reading/writing cursor to the specified position (in bytes from the beginning of the file).
  262. .. _class_File_method_seek_end:
  263. - void **seek_end** **(** :ref:`int<class_int>` position=0 **)**
  264. Changes the file reading/writing cursor to the specified position (in bytes from the end of the file).
  265. **Note:** This is an offset, so you should use negative numbers or the cursor will be at the end of the file.
  266. .. _class_File_method_store_16:
  267. - void **store_16** **(** :ref:`int<class_int>` value **)**
  268. Stores an integer as 16 bits in the file.
  269. .. _class_File_method_store_32:
  270. - void **store_32** **(** :ref:`int<class_int>` value **)**
  271. Stores an integer as 32 bits in the file.
  272. .. _class_File_method_store_64:
  273. - void **store_64** **(** :ref:`int<class_int>` value **)**
  274. Stores an integer as 64 bits in the file.
  275. .. _class_File_method_store_8:
  276. - void **store_8** **(** :ref:`int<class_int>` value **)**
  277. Stores an integer as 8 bits in the file.
  278. .. _class_File_method_store_buffer:
  279. - void **store_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  280. Stores the given array of bytes in the file.
  281. .. _class_File_method_store_csv_line:
  282. - void **store_csv_line** **(** :ref:`PoolStringArray<class_PoolStringArray>` values, :ref:`String<class_String>` delim="," **)**
  283. Store the given :ref:`PoolStringArray<class_PoolStringArray>` in the file as a line formatted in the CSV (Comma-Separated Values) format. You can pass a different delimiter ``delim`` to use other than the default ``","`` (comma). This delimiter must be one-character long.
  284. Text will be encoded as UTF-8.
  285. .. _class_File_method_store_double:
  286. - void **store_double** **(** :ref:`float<class_float>` value **)**
  287. Stores a floating-point number as 64 bits in the file.
  288. .. _class_File_method_store_float:
  289. - void **store_float** **(** :ref:`float<class_float>` value **)**
  290. Stores a floating-point number as 32 bits in the file.
  291. .. _class_File_method_store_line:
  292. - void **store_line** **(** :ref:`String<class_String>` line **)**
  293. Stores the given :ref:`String<class_String>` as a line in the file.
  294. Text will be encoded as UTF-8.
  295. .. _class_File_method_store_pascal_string:
  296. - void **store_pascal_string** **(** :ref:`String<class_String>` string **)**
  297. Stores the given :ref:`String<class_String>` as a line in the file in Pascal format (i.e. also store the length of the string).
  298. Text will be encoded as UTF-8.
  299. .. _class_File_method_store_real:
  300. - void **store_real** **(** :ref:`float<class_float>` value **)**
  301. Stores a floating-point number in the file.
  302. .. _class_File_method_store_string:
  303. - void **store_string** **(** :ref:`String<class_String>` string **)**
  304. Stores the given :ref:`String<class_String>` in the file.
  305. Text will be encoded as UTF-8.
  306. .. _class_File_method_store_var:
  307. - void **store_var** **(** :ref:`Variant<class_Variant>` value, :ref:`bool<class_bool>` full_objects=false **)**
  308. Stores any Variant value in the file. If ``full_objects`` is ``true``, encoding objects is allowed (and can potentially include code).