class_fileaccess.rst 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/FileAccess.xml.
  6. .. _class_FileAccess:
  7. FileAccess
  8. ==========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Provides methods for file reading and writing operations.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This class can be used to permanently store data in the user device's file system and to read from it. This is useful for storing game save data or player configuration files.
  15. \ **Example:** How to write and read from a file. The file named ``"save_game.dat"`` will be stored in the user data folder, as specified in the :doc:`Data paths <../tutorials/io/data_paths>` documentation:
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. func save_to_file(content):
  19. var file = FileAccess.open("user://save_game.dat", FileAccess.WRITE)
  20. file.store_string(content)
  21. func load_from_file():
  22. var file = FileAccess.open("user://save_game.dat", FileAccess.READ)
  23. var content = file.get_as_text()
  24. return content
  25. .. code-tab:: csharp
  26. public void SaveToFile(string content)
  27. {
  28. using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Write);
  29. file.StoreString(content);
  30. }
  31. public string LoadFromFile()
  32. {
  33. using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Read);
  34. string content = file.GetAsText();
  35. return content;
  36. }
  37. A **FileAccess** instance will close its file when the instance is freed. Since it inherits :ref:`RefCounted<class_RefCounted>`, this happens automatically when it is no longer in use. :ref:`close()<class_FileAccess_method_close>` can be called to close it earlier. In C#, the reference must be disposed manually, which can be done with the ``using`` statement or by calling the ``Dispose`` method directly.
  38. \ **Note:** To access project resources once exported, it is recommended to use :ref:`ResourceLoader<class_ResourceLoader>` instead of **FileAccess**, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package. If using **FileAccess**, make sure the file is included in the export by changing its import mode to **Keep File (exported as is)** in the Import dock, or, for files where this option is not available, change the non-resource export filter in the Export dialog to include the file's extension (e.g. ``*.txt``).
  39. \ **Note:** Files are automatically closed only if the process exits "normally" (such as by clicking the window manager's close button or pressing :kbd:`Alt + F4`). If you stop the project execution by pressing :kbd:`F8` while the project is running, the file won't be closed as the game process will be killed. You can work around this by calling :ref:`flush()<class_FileAccess_method_flush>` at regular intervals.
  40. .. rst-class:: classref-introduction-group
  41. Tutorials
  42. ---------
  43. - :doc:`File system <../tutorials/scripting/filesystem>`
  44. - :doc:`Runtime file loading and saving <../tutorials/io/runtime_file_loading_and_saving>`
  45. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/2755>`__
  46. .. rst-class:: classref-reftable-group
  47. Properties
  48. ----------
  49. .. table::
  50. :widths: auto
  51. +-------------------------+---------------------------------------------------------+
  52. | :ref:`bool<class_bool>` | :ref:`big_endian<class_FileAccess_property_big_endian>` |
  53. +-------------------------+---------------------------------------------------------+
  54. .. rst-class:: classref-reftable-group
  55. Methods
  56. -------
  57. .. table::
  58. :widths: auto
  59. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | |void| | :ref:`close<class_FileAccess_method_close>`\ (\ ) |
  61. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`FileAccess<class_FileAccess>` | :ref:`create_temp<class_FileAccess_method_create_temp>`\ (\ mode_flags\: :ref:`int<class_int>`, prefix\: :ref:`String<class_String>` = "", extension\: :ref:`String<class_String>` = "", keep\: :ref:`bool<class_bool>` = false\ ) |static| |
  63. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`eof_reached<class_FileAccess_method_eof_reached>`\ (\ ) |const| |
  65. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`bool<class_bool>` | :ref:`file_exists<class_FileAccess_method_file_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  67. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | |void| | :ref:`flush<class_FileAccess_method_flush>`\ (\ ) |
  69. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`int<class_int>` | :ref:`get_8<class_FileAccess_method_get_8>`\ (\ ) |const| |
  71. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`get_16<class_FileAccess_method_get_16>`\ (\ ) |const| |
  73. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`int<class_int>` | :ref:`get_32<class_FileAccess_method_get_32>`\ (\ ) |const| |
  75. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`int<class_int>` | :ref:`get_64<class_FileAccess_method_get_64>`\ (\ ) |const| |
  77. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`int<class_int>` | :ref:`get_access_time<class_FileAccess_method_get_access_time>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  79. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`String<class_String>` | :ref:`get_as_text<class_FileAccess_method_get_as_text>`\ (\ skip_cr\: :ref:`bool<class_bool>` = false\ ) |const| |
  81. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_buffer<class_FileAccess_method_get_buffer>`\ (\ length\: :ref:`int<class_int>`\ ) |const| |
  83. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_csv_line<class_FileAccess_method_get_csv_line>`\ (\ delim\: :ref:`String<class_String>` = ","\ ) |const| |
  85. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`float<class_float>` | :ref:`get_double<class_FileAccess_method_get_double>`\ (\ ) |const| |
  87. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_error<class_FileAccess_method_get_error>`\ (\ ) |const| |
  89. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_file_as_bytes<class_FileAccess_method_get_file_as_bytes>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  91. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`String<class_String>` | :ref:`get_file_as_string<class_FileAccess_method_get_file_as_string>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  93. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`float<class_float>` | :ref:`get_float<class_FileAccess_method_get_float>`\ (\ ) |const| |
  95. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`float<class_float>` | :ref:`get_half<class_FileAccess_method_get_half>`\ (\ ) |const| |
  97. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`get_hidden_attribute<class_FileAccess_method_get_hidden_attribute>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  99. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`int<class_int>` | :ref:`get_length<class_FileAccess_method_get_length>`\ (\ ) |const| |
  101. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`String<class_String>` | :ref:`get_line<class_FileAccess_method_get_line>`\ (\ ) |const| |
  103. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`String<class_String>` | :ref:`get_md5<class_FileAccess_method_get_md5>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  105. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`int<class_int>` | :ref:`get_modified_time<class_FileAccess_method_get_modified_time>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  107. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_open_error<class_FileAccess_method_get_open_error>`\ (\ ) |static| |
  109. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`String<class_String>` | :ref:`get_pascal_string<class_FileAccess_method_get_pascal_string>`\ (\ ) |
  111. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`String<class_String>` | :ref:`get_path<class_FileAccess_method_get_path>`\ (\ ) |const| |
  113. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`String<class_String>` | :ref:`get_path_absolute<class_FileAccess_method_get_path_absolute>`\ (\ ) |const| |
  115. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`int<class_int>` | :ref:`get_position<class_FileAccess_method_get_position>`\ (\ ) |const| |
  117. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`bool<class_bool>` | :ref:`get_read_only_attribute<class_FileAccess_method_get_read_only_attribute>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  119. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`float<class_float>` | :ref:`get_real<class_FileAccess_method_get_real>`\ (\ ) |const| |
  121. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`String<class_String>` | :ref:`get_sha256<class_FileAccess_method_get_sha256>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  123. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`int<class_int>` | :ref:`get_size<class_FileAccess_method_get_size>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  125. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\] | :ref:`get_unix_permissions<class_FileAccess_method_get_unix_permissions>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  127. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_FileAccess_method_get_var>`\ (\ allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| |
  129. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`bool<class_bool>` | :ref:`is_open<class_FileAccess_method_is_open>`\ (\ ) |const| |
  131. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`FileAccess<class_FileAccess>` | :ref:`open<class_FileAccess_method_open>`\ (\ path\: :ref:`String<class_String>`, flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`\ ) |static| |
  133. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`FileAccess<class_FileAccess>` | :ref:`open_compressed<class_FileAccess_method_open_compressed>`\ (\ path\: :ref:`String<class_String>`, mode_flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`, compression_mode\: :ref:`CompressionMode<enum_FileAccess_CompressionMode>` = 0\ ) |static| |
  135. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :ref:`FileAccess<class_FileAccess>` | :ref:`open_encrypted<class_FileAccess_method_open_encrypted>`\ (\ path\: :ref:`String<class_String>`, mode_flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`, key\: :ref:`PackedByteArray<class_PackedByteArray>`, iv\: :ref:`PackedByteArray<class_PackedByteArray>` = PackedByteArray()\ ) |static| |
  137. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`FileAccess<class_FileAccess>` | :ref:`open_encrypted_with_pass<class_FileAccess_method_open_encrypted_with_pass>`\ (\ path\: :ref:`String<class_String>`, mode_flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`, pass\: :ref:`String<class_String>`\ ) |static| |
  139. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`resize<class_FileAccess_method_resize>`\ (\ length\: :ref:`int<class_int>`\ ) |
  141. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | |void| | :ref:`seek<class_FileAccess_method_seek>`\ (\ position\: :ref:`int<class_int>`\ ) |
  143. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | |void| | :ref:`seek_end<class_FileAccess_method_seek_end>`\ (\ position\: :ref:`int<class_int>` = 0\ ) |
  145. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`set_hidden_attribute<class_FileAccess_method_set_hidden_attribute>`\ (\ file\: :ref:`String<class_String>`, hidden\: :ref:`bool<class_bool>`\ ) |static| |
  147. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`set_read_only_attribute<class_FileAccess_method_set_read_only_attribute>`\ (\ file\: :ref:`String<class_String>`, ro\: :ref:`bool<class_bool>`\ ) |static| |
  149. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`set_unix_permissions<class_FileAccess_method_set_unix_permissions>`\ (\ file\: :ref:`String<class_String>`, permissions\: |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\]\ ) |static| |
  151. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`bool<class_bool>` | :ref:`store_8<class_FileAccess_method_store_8>`\ (\ value\: :ref:`int<class_int>`\ ) |
  153. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`bool<class_bool>` | :ref:`store_16<class_FileAccess_method_store_16>`\ (\ value\: :ref:`int<class_int>`\ ) |
  155. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`bool<class_bool>` | :ref:`store_32<class_FileAccess_method_store_32>`\ (\ value\: :ref:`int<class_int>`\ ) |
  157. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`bool<class_bool>` | :ref:`store_64<class_FileAccess_method_store_64>`\ (\ value\: :ref:`int<class_int>`\ ) |
  159. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`bool<class_bool>` | :ref:`store_buffer<class_FileAccess_method_store_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
  161. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`bool<class_bool>` | :ref:`store_csv_line<class_FileAccess_method_store_csv_line>`\ (\ values\: :ref:`PackedStringArray<class_PackedStringArray>`, delim\: :ref:`String<class_String>` = ","\ ) |
  163. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`bool<class_bool>` | :ref:`store_double<class_FileAccess_method_store_double>`\ (\ value\: :ref:`float<class_float>`\ ) |
  165. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`bool<class_bool>` | :ref:`store_float<class_FileAccess_method_store_float>`\ (\ value\: :ref:`float<class_float>`\ ) |
  167. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`bool<class_bool>` | :ref:`store_half<class_FileAccess_method_store_half>`\ (\ value\: :ref:`float<class_float>`\ ) |
  169. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`bool<class_bool>` | :ref:`store_line<class_FileAccess_method_store_line>`\ (\ line\: :ref:`String<class_String>`\ ) |
  171. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`bool<class_bool>` | :ref:`store_pascal_string<class_FileAccess_method_store_pascal_string>`\ (\ string\: :ref:`String<class_String>`\ ) |
  173. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`bool<class_bool>` | :ref:`store_real<class_FileAccess_method_store_real>`\ (\ value\: :ref:`float<class_float>`\ ) |
  175. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  176. | :ref:`bool<class_bool>` | :ref:`store_string<class_FileAccess_method_store_string>`\ (\ string\: :ref:`String<class_String>`\ ) |
  177. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  178. | :ref:`bool<class_bool>` | :ref:`store_var<class_FileAccess_method_store_var>`\ (\ value\: :ref:`Variant<class_Variant>`, full_objects\: :ref:`bool<class_bool>` = false\ ) |
  179. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  180. .. rst-class:: classref-section-separator
  181. ----
  182. .. rst-class:: classref-descriptions-group
  183. Enumerations
  184. ------------
  185. .. _enum_FileAccess_ModeFlags:
  186. .. rst-class:: classref-enumeration
  187. enum **ModeFlags**: :ref:`๐Ÿ”—<enum_FileAccess_ModeFlags>`
  188. .. _class_FileAccess_constant_READ:
  189. .. rst-class:: classref-enumeration-constant
  190. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **READ** = ``1``
  191. Opens the file for read operations. The cursor is positioned at the beginning of the file.
  192. .. _class_FileAccess_constant_WRITE:
  193. .. rst-class:: classref-enumeration-constant
  194. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **WRITE** = ``2``
  195. Opens the file for write operations. The file is created if it does not exist, and truncated if it does.
  196. \ **Note:** When creating a file it must be in an already existing directory. To recursively create directories for a file path, see :ref:`DirAccess.make_dir_recursive()<class_DirAccess_method_make_dir_recursive>`.
  197. .. _class_FileAccess_constant_READ_WRITE:
  198. .. rst-class:: classref-enumeration-constant
  199. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **READ_WRITE** = ``3``
  200. Opens the file for read and write operations. Does not truncate the file. The cursor is positioned at the beginning of the file.
  201. .. _class_FileAccess_constant_WRITE_READ:
  202. .. rst-class:: classref-enumeration-constant
  203. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **WRITE_READ** = ``7``
  204. Opens the file for read and write operations. The file is created if it does not exist, and truncated if it does. The cursor is positioned at the beginning of the file.
  205. \ **Note:** When creating a file it must be in an already existing directory. To recursively create directories for a file path, see :ref:`DirAccess.make_dir_recursive()<class_DirAccess_method_make_dir_recursive>`.
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _enum_FileAccess_CompressionMode:
  209. .. rst-class:: classref-enumeration
  210. enum **CompressionMode**: :ref:`๐Ÿ”—<enum_FileAccess_CompressionMode>`
  211. .. _class_FileAccess_constant_COMPRESSION_FASTLZ:
  212. .. rst-class:: classref-enumeration-constant
  213. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_FASTLZ** = ``0``
  214. Uses the `FastLZ <https://fastlz.org/>`__ compression method.
  215. .. _class_FileAccess_constant_COMPRESSION_DEFLATE:
  216. .. rst-class:: classref-enumeration-constant
  217. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_DEFLATE** = ``1``
  218. Uses the `DEFLATE <https://en.wikipedia.org/wiki/DEFLATE>`__ compression method.
  219. .. _class_FileAccess_constant_COMPRESSION_ZSTD:
  220. .. rst-class:: classref-enumeration-constant
  221. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_ZSTD** = ``2``
  222. Uses the `Zstandard <https://facebook.github.io/zstd/>`__ compression method.
  223. .. _class_FileAccess_constant_COMPRESSION_GZIP:
  224. .. rst-class:: classref-enumeration-constant
  225. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_GZIP** = ``3``
  226. Uses the `gzip <https://www.gzip.org/>`__ compression method.
  227. .. _class_FileAccess_constant_COMPRESSION_BROTLI:
  228. .. rst-class:: classref-enumeration-constant
  229. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_BROTLI** = ``4``
  230. Uses the `brotli <https://github.com/google/brotli>`__ compression method (only decompression is supported).
  231. .. rst-class:: classref-item-separator
  232. ----
  233. .. _enum_FileAccess_UnixPermissionFlags:
  234. .. rst-class:: classref-enumeration
  235. flags **UnixPermissionFlags**: :ref:`๐Ÿ”—<enum_FileAccess_UnixPermissionFlags>`
  236. .. _class_FileAccess_constant_UNIX_READ_OWNER:
  237. .. rst-class:: classref-enumeration-constant
  238. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_OWNER** = ``256``
  239. Read for owner bit.
  240. .. _class_FileAccess_constant_UNIX_WRITE_OWNER:
  241. .. rst-class:: classref-enumeration-constant
  242. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_OWNER** = ``128``
  243. Write for owner bit.
  244. .. _class_FileAccess_constant_UNIX_EXECUTE_OWNER:
  245. .. rst-class:: classref-enumeration-constant
  246. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_OWNER** = ``64``
  247. Execute for owner bit.
  248. .. _class_FileAccess_constant_UNIX_READ_GROUP:
  249. .. rst-class:: classref-enumeration-constant
  250. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_GROUP** = ``32``
  251. Read for group bit.
  252. .. _class_FileAccess_constant_UNIX_WRITE_GROUP:
  253. .. rst-class:: classref-enumeration-constant
  254. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_GROUP** = ``16``
  255. Write for group bit.
  256. .. _class_FileAccess_constant_UNIX_EXECUTE_GROUP:
  257. .. rst-class:: classref-enumeration-constant
  258. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_GROUP** = ``8``
  259. Execute for group bit.
  260. .. _class_FileAccess_constant_UNIX_READ_OTHER:
  261. .. rst-class:: classref-enumeration-constant
  262. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_OTHER** = ``4``
  263. Read for other bit.
  264. .. _class_FileAccess_constant_UNIX_WRITE_OTHER:
  265. .. rst-class:: classref-enumeration-constant
  266. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_OTHER** = ``2``
  267. Write for other bit.
  268. .. _class_FileAccess_constant_UNIX_EXECUTE_OTHER:
  269. .. rst-class:: classref-enumeration-constant
  270. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_OTHER** = ``1``
  271. Execute for other bit.
  272. .. _class_FileAccess_constant_UNIX_SET_USER_ID:
  273. .. rst-class:: classref-enumeration-constant
  274. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_SET_USER_ID** = ``2048``
  275. Set user id on execution bit.
  276. .. _class_FileAccess_constant_UNIX_SET_GROUP_ID:
  277. .. rst-class:: classref-enumeration-constant
  278. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_SET_GROUP_ID** = ``1024``
  279. Set group id on execution bit.
  280. .. _class_FileAccess_constant_UNIX_RESTRICTED_DELETE:
  281. .. rst-class:: classref-enumeration-constant
  282. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_RESTRICTED_DELETE** = ``512``
  283. Restricted deletion (sticky) bit.
  284. .. rst-class:: classref-section-separator
  285. ----
  286. .. rst-class:: classref-descriptions-group
  287. Property Descriptions
  288. ---------------------
  289. .. _class_FileAccess_property_big_endian:
  290. .. rst-class:: classref-property
  291. :ref:`bool<class_bool>` **big_endian** :ref:`๐Ÿ”—<class_FileAccess_property_big_endian>`
  292. .. rst-class:: classref-property-setget
  293. - |void| **set_big_endian**\ (\ value\: :ref:`bool<class_bool>`\ )
  294. - :ref:`bool<class_bool>` **is_big_endian**\ (\ )
  295. If ``true``, the file is read with big-endian `endianness <https://en.wikipedia.org/wiki/Endianness>`__. If ``false``, the file is read with little-endian endianness. If in doubt, leave this to ``false`` as most files are written with little-endian endianness.
  296. \ **Note:** This is always reset to system endianness, which is little-endian on all supported platforms, whenever you open the file. Therefore, you must set :ref:`big_endian<class_FileAccess_property_big_endian>` *after* opening the file, not before.
  297. .. rst-class:: classref-section-separator
  298. ----
  299. .. rst-class:: classref-descriptions-group
  300. Method Descriptions
  301. -------------------
  302. .. _class_FileAccess_method_close:
  303. .. rst-class:: classref-method
  304. |void| **close**\ (\ ) :ref:`๐Ÿ”—<class_FileAccess_method_close>`
  305. Closes the currently opened file and prevents subsequent read/write operations. Use :ref:`flush()<class_FileAccess_method_flush>` to persist the data to disk without closing the file.
  306. \ **Note:** **FileAccess** will automatically close when it's freed, which happens when it goes out of scope or when it gets assigned with ``null``. In C# the reference must be disposed after we are done using it, this can be done with the ``using`` statement or calling the ``Dispose`` method directly.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_FileAccess_method_create_temp:
  310. .. rst-class:: classref-method
  311. :ref:`FileAccess<class_FileAccess>` **create_temp**\ (\ mode_flags\: :ref:`int<class_int>`, prefix\: :ref:`String<class_String>` = "", extension\: :ref:`String<class_String>` = "", keep\: :ref:`bool<class_bool>` = false\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_create_temp>`
  312. Creates a temporary file. This file will be freed when the returned **FileAccess** is freed.
  313. If ``prefix`` is not empty, it will be prefixed to the file name, separated by a ``-``.
  314. If ``extension`` is not empty, it will be appended to the temporary file name.
  315. If ``keep`` is ``true``, the file is not deleted when the returned **FileAccess** is freed.
  316. Returns ``null`` if opening the file failed. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  317. .. rst-class:: classref-item-separator
  318. ----
  319. .. _class_FileAccess_method_eof_reached:
  320. .. rst-class:: classref-method
  321. :ref:`bool<class_bool>` **eof_reached**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_eof_reached>`
  322. Returns ``true`` if the file cursor has already read past the end of the file.
  323. \ **Note:** ``eof_reached() == false`` cannot be used to check whether there is more data available. To loop while there is more data available, use:
  324. .. tabs::
  325. .. code-tab:: gdscript
  326. while file.get_position() < file.get_length():
  327. # Read data
  328. .. code-tab:: csharp
  329. while (file.GetPosition() < file.GetLength())
  330. {
  331. // Read data
  332. }
  333. .. rst-class:: classref-item-separator
  334. ----
  335. .. _class_FileAccess_method_file_exists:
  336. .. rst-class:: classref-method
  337. :ref:`bool<class_bool>` **file_exists**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_file_exists>`
  338. Returns ``true`` if the file exists in the given path.
  339. \ **Note:** Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. See :ref:`ResourceLoader.exists()<class_ResourceLoader_method_exists>` for an alternative approach that takes resource remapping into account.
  340. For a non-static, relative equivalent, use :ref:`DirAccess.file_exists()<class_DirAccess_method_file_exists>`.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_FileAccess_method_flush:
  344. .. rst-class:: classref-method
  345. |void| **flush**\ (\ ) :ref:`๐Ÿ”—<class_FileAccess_method_flush>`
  346. Writes the file's buffer to disk. Flushing is automatically performed when the file is closed. This means you don't need to call :ref:`flush()<class_FileAccess_method_flush>` manually before closing a file. Still, calling :ref:`flush()<class_FileAccess_method_flush>` can be used to ensure the data is safe even if the project crashes instead of being closed gracefully.
  347. \ **Note:** Only call :ref:`flush()<class_FileAccess_method_flush>` when you actually need it. Otherwise, it will decrease performance due to constant disk writes.
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_FileAccess_method_get_8:
  351. .. rst-class:: classref-method
  352. :ref:`int<class_int>` **get_8**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_8>`
  353. Returns the next 8 bits from the file as an integer. See :ref:`store_8()<class_FileAccess_method_store_8>` for details on what values can be stored and retrieved this way.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_FileAccess_method_get_16:
  357. .. rst-class:: classref-method
  358. :ref:`int<class_int>` **get_16**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_16>`
  359. Returns the next 16 bits from the file as an integer. See :ref:`store_16()<class_FileAccess_method_store_16>` for details on what values can be stored and retrieved this way.
  360. .. rst-class:: classref-item-separator
  361. ----
  362. .. _class_FileAccess_method_get_32:
  363. .. rst-class:: classref-method
  364. :ref:`int<class_int>` **get_32**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_32>`
  365. Returns the next 32 bits from the file as an integer. See :ref:`store_32()<class_FileAccess_method_store_32>` for details on what values can be stored and retrieved this way.
  366. .. rst-class:: classref-item-separator
  367. ----
  368. .. _class_FileAccess_method_get_64:
  369. .. rst-class:: classref-method
  370. :ref:`int<class_int>` **get_64**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_64>`
  371. Returns the next 64 bits from the file as an integer. See :ref:`store_64()<class_FileAccess_method_store_64>` for details on what values can be stored and retrieved this way.
  372. .. rst-class:: classref-item-separator
  373. ----
  374. .. _class_FileAccess_method_get_access_time:
  375. .. rst-class:: classref-method
  376. :ref:`int<class_int>` **get_access_time**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_access_time>`
  377. Returns the last time the ``file`` was accessed in Unix timestamp format, or ``0`` on error. This Unix timestamp can be converted to another format using the :ref:`Time<class_Time>` singleton.
  378. .. rst-class:: classref-item-separator
  379. ----
  380. .. _class_FileAccess_method_get_as_text:
  381. .. rst-class:: classref-method
  382. :ref:`String<class_String>` **get_as_text**\ (\ skip_cr\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_as_text>`
  383. Returns the whole file as a :ref:`String<class_String>`. Text is interpreted as being UTF-8 encoded.
  384. If ``skip_cr`` is ``true``, carriage return characters (``\r``, CR) will be ignored when parsing the UTF-8, so that only line feed characters (``\n``, LF) represent a new line (Unix convention).
  385. .. rst-class:: classref-item-separator
  386. ----
  387. .. _class_FileAccess_method_get_buffer:
  388. .. rst-class:: classref-method
  389. :ref:`PackedByteArray<class_PackedByteArray>` **get_buffer**\ (\ length\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_buffer>`
  390. Returns next ``length`` bytes of the file as a :ref:`PackedByteArray<class_PackedByteArray>`.
  391. .. rst-class:: classref-item-separator
  392. ----
  393. .. _class_FileAccess_method_get_csv_line:
  394. .. rst-class:: classref-method
  395. :ref:`PackedStringArray<class_PackedStringArray>` **get_csv_line**\ (\ delim\: :ref:`String<class_String>` = ","\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_csv_line>`
  396. 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, and cannot be a double quotation mark.
  397. Text is interpreted as being UTF-8 encoded. Text values must be enclosed in double quotes if they include the delimiter character. Double quotes within a text value can be escaped by doubling their occurrence.
  398. For example, the following CSV lines are valid and will be properly parsed as two strings each:
  399. .. code:: text
  400. Alice,"Hello, Bob!"
  401. Bob,Alice! What a surprise!
  402. Alice,"I thought you'd reply with ""Hello, world""."
  403. Note how the second line can omit the enclosing quotes as it does not include the delimiter. However it *could* very well use quotes, it was only written without for demonstration purposes. The third line must use ``""`` for each quotation mark that needs to be interpreted as such instead of the end of a text value.
  404. .. rst-class:: classref-item-separator
  405. ----
  406. .. _class_FileAccess_method_get_double:
  407. .. rst-class:: classref-method
  408. :ref:`float<class_float>` **get_double**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_double>`
  409. Returns the next 64 bits from the file as a floating-point number.
  410. .. rst-class:: classref-item-separator
  411. ----
  412. .. _class_FileAccess_method_get_error:
  413. .. rst-class:: classref-method
  414. :ref:`Error<enum_@GlobalScope_Error>` **get_error**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_error>`
  415. Returns the last error that happened when trying to perform operations. Compare with the ``ERR_FILE_*`` constants from :ref:`Error<enum_@GlobalScope_Error>`.
  416. .. rst-class:: classref-item-separator
  417. ----
  418. .. _class_FileAccess_method_get_file_as_bytes:
  419. .. rst-class:: classref-method
  420. :ref:`PackedByteArray<class_PackedByteArray>` **get_file_as_bytes**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_file_as_bytes>`
  421. Returns the whole ``path`` file contents as a :ref:`PackedByteArray<class_PackedByteArray>` without any decoding.
  422. Returns an empty :ref:`PackedByteArray<class_PackedByteArray>` if an error occurred while opening the file. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  423. .. rst-class:: classref-item-separator
  424. ----
  425. .. _class_FileAccess_method_get_file_as_string:
  426. .. rst-class:: classref-method
  427. :ref:`String<class_String>` **get_file_as_string**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_file_as_string>`
  428. Returns the whole ``path`` file contents as a :ref:`String<class_String>`. Text is interpreted as being UTF-8 encoded.
  429. Returns an empty :ref:`String<class_String>` if an error occurred while opening the file. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  430. .. rst-class:: classref-item-separator
  431. ----
  432. .. _class_FileAccess_method_get_float:
  433. .. rst-class:: classref-method
  434. :ref:`float<class_float>` **get_float**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_float>`
  435. Returns the next 32 bits from the file as a floating-point number.
  436. .. rst-class:: classref-item-separator
  437. ----
  438. .. _class_FileAccess_method_get_half:
  439. .. rst-class:: classref-method
  440. :ref:`float<class_float>` **get_half**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_half>`
  441. Returns the next 16 bits from the file as a half-precision floating-point number.
  442. .. rst-class:: classref-item-separator
  443. ----
  444. .. _class_FileAccess_method_get_hidden_attribute:
  445. .. rst-class:: classref-method
  446. :ref:`bool<class_bool>` **get_hidden_attribute**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_hidden_attribute>`
  447. Returns ``true``, if file ``hidden`` attribute is set.
  448. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  449. .. rst-class:: classref-item-separator
  450. ----
  451. .. _class_FileAccess_method_get_length:
  452. .. rst-class:: classref-method
  453. :ref:`int<class_int>` **get_length**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_length>`
  454. Returns the size of the file in bytes. For a pipe, returns the number of bytes available for reading from the pipe.
  455. .. rst-class:: classref-item-separator
  456. ----
  457. .. _class_FileAccess_method_get_line:
  458. .. rst-class:: classref-method
  459. :ref:`String<class_String>` **get_line**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_line>`
  460. Returns the next line of the file as a :ref:`String<class_String>`. The returned string doesn't include newline (``\n``) or carriage return (``\r``) characters, but does include any other leading or trailing whitespace.
  461. Text is interpreted as being UTF-8 encoded.
  462. .. rst-class:: classref-item-separator
  463. ----
  464. .. _class_FileAccess_method_get_md5:
  465. .. rst-class:: classref-method
  466. :ref:`String<class_String>` **get_md5**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_md5>`
  467. Returns an MD5 String representing the file at the given path or an empty :ref:`String<class_String>` on failure.
  468. .. rst-class:: classref-item-separator
  469. ----
  470. .. _class_FileAccess_method_get_modified_time:
  471. .. rst-class:: classref-method
  472. :ref:`int<class_int>` **get_modified_time**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_modified_time>`
  473. Returns the last time the ``file`` was modified in Unix timestamp format, or ``0`` on error. This Unix timestamp can be converted to another format using the :ref:`Time<class_Time>` singleton.
  474. .. rst-class:: classref-item-separator
  475. ----
  476. .. _class_FileAccess_method_get_open_error:
  477. .. rst-class:: classref-method
  478. :ref:`Error<enum_@GlobalScope_Error>` **get_open_error**\ (\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_open_error>`
  479. Returns the result of the last :ref:`open()<class_FileAccess_method_open>` call in the current thread.
  480. .. rst-class:: classref-item-separator
  481. ----
  482. .. _class_FileAccess_method_get_pascal_string:
  483. .. rst-class:: classref-method
  484. :ref:`String<class_String>` **get_pascal_string**\ (\ ) :ref:`๐Ÿ”—<class_FileAccess_method_get_pascal_string>`
  485. Returns a :ref:`String<class_String>` saved in Pascal format from the file.
  486. Text is interpreted as being UTF-8 encoded.
  487. .. rst-class:: classref-item-separator
  488. ----
  489. .. _class_FileAccess_method_get_path:
  490. .. rst-class:: classref-method
  491. :ref:`String<class_String>` **get_path**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_path>`
  492. Returns the path as a :ref:`String<class_String>` for the current open file.
  493. .. rst-class:: classref-item-separator
  494. ----
  495. .. _class_FileAccess_method_get_path_absolute:
  496. .. rst-class:: classref-method
  497. :ref:`String<class_String>` **get_path_absolute**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_path_absolute>`
  498. Returns the absolute path as a :ref:`String<class_String>` for the current open file.
  499. .. rst-class:: classref-item-separator
  500. ----
  501. .. _class_FileAccess_method_get_position:
  502. .. rst-class:: classref-method
  503. :ref:`int<class_int>` **get_position**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_position>`
  504. Returns the file cursor's position.
  505. .. rst-class:: classref-item-separator
  506. ----
  507. .. _class_FileAccess_method_get_read_only_attribute:
  508. .. rst-class:: classref-method
  509. :ref:`bool<class_bool>` **get_read_only_attribute**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_read_only_attribute>`
  510. Returns ``true``, if file ``read only`` attribute is set.
  511. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  512. .. rst-class:: classref-item-separator
  513. ----
  514. .. _class_FileAccess_method_get_real:
  515. .. rst-class:: classref-method
  516. :ref:`float<class_float>` **get_real**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_real>`
  517. Returns the next bits from the file as a floating-point number.
  518. .. rst-class:: classref-item-separator
  519. ----
  520. .. _class_FileAccess_method_get_sha256:
  521. .. rst-class:: classref-method
  522. :ref:`String<class_String>` **get_sha256**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_sha256>`
  523. Returns an SHA-256 :ref:`String<class_String>` representing the file at the given path or an empty :ref:`String<class_String>` on failure.
  524. .. rst-class:: classref-item-separator
  525. ----
  526. .. _class_FileAccess_method_get_size:
  527. .. rst-class:: classref-method
  528. :ref:`int<class_int>` **get_size**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_size>`
  529. Returns file size in bytes, or ``-1`` on error.
  530. .. rst-class:: classref-item-separator
  531. ----
  532. .. _class_FileAccess_method_get_unix_permissions:
  533. .. rst-class:: classref-method
  534. |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\] **get_unix_permissions**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_unix_permissions>`
  535. Returns file UNIX permissions.
  536. \ **Note:** This method is implemented on iOS, Linux/BSD, and macOS.
  537. .. rst-class:: classref-item-separator
  538. ----
  539. .. _class_FileAccess_method_get_var:
  540. .. rst-class:: classref-method
  541. :ref:`Variant<class_Variant>` **get_var**\ (\ allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_var>`
  542. Returns the next :ref:`Variant<class_Variant>` value from the file. If ``allow_objects`` is ``true``, decoding objects is allowed.
  543. Internally, this uses the same decoding mechanism as the :ref:`@GlobalScope.bytes_to_var()<class_@GlobalScope_method_bytes_to_var>` method.
  544. \ **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.
  545. .. rst-class:: classref-item-separator
  546. ----
  547. .. _class_FileAccess_method_is_open:
  548. .. rst-class:: classref-method
  549. :ref:`bool<class_bool>` **is_open**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_is_open>`
  550. Returns ``true`` if the file is currently opened.
  551. .. rst-class:: classref-item-separator
  552. ----
  553. .. _class_FileAccess_method_open:
  554. .. rst-class:: classref-method
  555. :ref:`FileAccess<class_FileAccess>` **open**\ (\ path\: :ref:`String<class_String>`, flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_open>`
  556. Creates a new **FileAccess** object and opens the file for writing or reading, depending on the flags.
  557. Returns ``null`` if opening the file failed. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  558. .. rst-class:: classref-item-separator
  559. ----
  560. .. _class_FileAccess_method_open_compressed:
  561. .. rst-class:: classref-method
  562. :ref:`FileAccess<class_FileAccess>` **open_compressed**\ (\ path\: :ref:`String<class_String>`, mode_flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`, compression_mode\: :ref:`CompressionMode<enum_FileAccess_CompressionMode>` = 0\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_open_compressed>`
  563. Creates a new **FileAccess** object and opens a compressed file for reading or writing.
  564. \ **Note:** :ref:`open_compressed()<class_FileAccess_method_open_compressed>` can only read files that were saved by Godot, not third-party compression formats. See `GitHub issue #28999 <https://github.com/godotengine/godot/issues/28999>`__ for a workaround.
  565. Returns ``null`` if opening the file failed. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  566. .. rst-class:: classref-item-separator
  567. ----
  568. .. _class_FileAccess_method_open_encrypted:
  569. .. rst-class:: classref-method
  570. :ref:`FileAccess<class_FileAccess>` **open_encrypted**\ (\ path\: :ref:`String<class_String>`, mode_flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`, key\: :ref:`PackedByteArray<class_PackedByteArray>`, iv\: :ref:`PackedByteArray<class_PackedByteArray>` = PackedByteArray()\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_open_encrypted>`
  571. Creates a new **FileAccess** object and opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it.
  572. \ **Note:** The provided key must be 32 bytes long.
  573. Returns ``null`` if opening the file failed. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  574. .. rst-class:: classref-item-separator
  575. ----
  576. .. _class_FileAccess_method_open_encrypted_with_pass:
  577. .. rst-class:: classref-method
  578. :ref:`FileAccess<class_FileAccess>` **open_encrypted_with_pass**\ (\ path\: :ref:`String<class_String>`, mode_flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`, pass\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_open_encrypted_with_pass>`
  579. Creates a new **FileAccess** object and opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it.
  580. Returns ``null`` if opening the file failed. You can use :ref:`get_open_error()<class_FileAccess_method_get_open_error>` to check the error that occurred.
  581. .. rst-class:: classref-item-separator
  582. ----
  583. .. _class_FileAccess_method_resize:
  584. .. rst-class:: classref-method
  585. :ref:`Error<enum_@GlobalScope_Error>` **resize**\ (\ length\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_resize>`
  586. Resizes the file to a specified length. The file must be open in a mode that permits writing. If the file is extended, NUL characters are appended. If the file is truncated, all data from the end file to the original length of the file is lost.
  587. .. rst-class:: classref-item-separator
  588. ----
  589. .. _class_FileAccess_method_seek:
  590. .. rst-class:: classref-method
  591. |void| **seek**\ (\ position\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_seek>`
  592. Changes the file reading/writing cursor to the specified position (in bytes from the beginning of the file).
  593. .. rst-class:: classref-item-separator
  594. ----
  595. .. _class_FileAccess_method_seek_end:
  596. .. rst-class:: classref-method
  597. |void| **seek_end**\ (\ position\: :ref:`int<class_int>` = 0\ ) :ref:`๐Ÿ”—<class_FileAccess_method_seek_end>`
  598. Changes the file reading/writing cursor to the specified position (in bytes from the end of the file).
  599. \ **Note:** This is an offset, so you should use negative numbers or the cursor will be at the end of the file.
  600. .. rst-class:: classref-item-separator
  601. ----
  602. .. _class_FileAccess_method_set_hidden_attribute:
  603. .. rst-class:: classref-method
  604. :ref:`Error<enum_@GlobalScope_Error>` **set_hidden_attribute**\ (\ file\: :ref:`String<class_String>`, hidden\: :ref:`bool<class_bool>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_set_hidden_attribute>`
  605. Sets file **hidden** attribute.
  606. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  607. .. rst-class:: classref-item-separator
  608. ----
  609. .. _class_FileAccess_method_set_read_only_attribute:
  610. .. rst-class:: classref-method
  611. :ref:`Error<enum_@GlobalScope_Error>` **set_read_only_attribute**\ (\ file\: :ref:`String<class_String>`, ro\: :ref:`bool<class_bool>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_set_read_only_attribute>`
  612. Sets file **read only** attribute.
  613. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  614. .. rst-class:: classref-item-separator
  615. ----
  616. .. _class_FileAccess_method_set_unix_permissions:
  617. .. rst-class:: classref-method
  618. :ref:`Error<enum_@GlobalScope_Error>` **set_unix_permissions**\ (\ file\: :ref:`String<class_String>`, permissions\: |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\]\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_set_unix_permissions>`
  619. Sets file UNIX permissions.
  620. \ **Note:** This method is implemented on iOS, Linux/BSD, and macOS.
  621. .. rst-class:: classref-item-separator
  622. ----
  623. .. _class_FileAccess_method_store_8:
  624. .. rst-class:: classref-method
  625. :ref:`bool<class_bool>` **store_8**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_8>`
  626. Stores an integer as 8 bits in the file.
  627. \ **Note:** The ``value`` should lie in the interval ``[0, 255]``. Any other value will overflow and wrap around.
  628. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  629. To store a signed integer, use :ref:`store_64()<class_FileAccess_method_store_64>`, or convert it manually (see :ref:`store_16()<class_FileAccess_method_store_16>` for an example).
  630. .. rst-class:: classref-item-separator
  631. ----
  632. .. _class_FileAccess_method_store_16:
  633. .. rst-class:: classref-method
  634. :ref:`bool<class_bool>` **store_16**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_16>`
  635. Stores an integer as 16 bits in the file.
  636. \ **Note:** The ``value`` should lie in the interval ``[0, 2^16 - 1]``. Any other value will overflow and wrap around.
  637. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  638. To store a signed integer, use :ref:`store_64()<class_FileAccess_method_store_64>` or store a signed integer from the interval ``[-2^15, 2^15 - 1]`` (i.e. keeping one bit for the signedness) and compute its sign manually when reading. For example:
  639. .. tabs::
  640. .. code-tab:: gdscript
  641. const MAX_15B = 1 << 15
  642. const MAX_16B = 1 << 16
  643. func unsigned16_to_signed(unsigned):
  644. return (unsigned + MAX_15B) % MAX_16B - MAX_15B
  645. func _ready():
  646. var f = FileAccess.open("user://file.dat", FileAccess.WRITE_READ)
  647. f.store_16(-42) # This wraps around and stores 65494 (2^16 - 42).
  648. f.store_16(121) # In bounds, will store 121.
  649. f.seek(0) # Go back to start to read the stored value.
  650. var read1 = f.get_16() # 65494
  651. var read2 = f.get_16() # 121
  652. var converted1 = unsigned16_to_signed(read1) # -42
  653. var converted2 = unsigned16_to_signed(read2) # 121
  654. .. code-tab:: csharp
  655. public override void _Ready()
  656. {
  657. using var f = FileAccess.Open("user://file.dat", FileAccess.ModeFlags.WriteRead);
  658. f.Store16(unchecked((ushort)-42)); // This wraps around and stores 65494 (2^16 - 42).
  659. f.Store16(121); // In bounds, will store 121.
  660. f.Seek(0); // Go back to start to read the stored value.
  661. ushort read1 = f.Get16(); // 65494
  662. ushort read2 = f.Get16(); // 121
  663. short converted1 = (short)read1; // -42
  664. short converted2 = (short)read2; // 121
  665. }
  666. .. rst-class:: classref-item-separator
  667. ----
  668. .. _class_FileAccess_method_store_32:
  669. .. rst-class:: classref-method
  670. :ref:`bool<class_bool>` **store_32**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_32>`
  671. Stores an integer as 32 bits in the file.
  672. \ **Note:** The ``value`` should lie in the interval ``[0, 2^32 - 1]``. Any other value will overflow and wrap around.
  673. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  674. To store a signed integer, use :ref:`store_64()<class_FileAccess_method_store_64>`, or convert it manually (see :ref:`store_16()<class_FileAccess_method_store_16>` for an example).
  675. .. rst-class:: classref-item-separator
  676. ----
  677. .. _class_FileAccess_method_store_64:
  678. .. rst-class:: classref-method
  679. :ref:`bool<class_bool>` **store_64**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_64>`
  680. Stores an integer as 64 bits in the file.
  681. \ **Note:** The ``value`` must lie in the interval ``[-2^63, 2^63 - 1]`` (i.e. be a valid :ref:`int<class_int>` value).
  682. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  683. .. rst-class:: classref-item-separator
  684. ----
  685. .. _class_FileAccess_method_store_buffer:
  686. .. rst-class:: classref-method
  687. :ref:`bool<class_bool>` **store_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_buffer>`
  688. Stores the given array of bytes in the file.
  689. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  690. .. rst-class:: classref-item-separator
  691. ----
  692. .. _class_FileAccess_method_store_csv_line:
  693. .. rst-class:: classref-method
  694. :ref:`bool<class_bool>` **store_csv_line**\ (\ values\: :ref:`PackedStringArray<class_PackedStringArray>`, delim\: :ref:`String<class_String>` = ","\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_csv_line>`
  695. Store the given :ref:`PackedStringArray<class_PackedStringArray>` 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.
  696. Text will be encoded as UTF-8.
  697. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  698. .. rst-class:: classref-item-separator
  699. ----
  700. .. _class_FileAccess_method_store_double:
  701. .. rst-class:: classref-method
  702. :ref:`bool<class_bool>` **store_double**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_double>`
  703. Stores a floating-point number as 64 bits in the file.
  704. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  705. .. rst-class:: classref-item-separator
  706. ----
  707. .. _class_FileAccess_method_store_float:
  708. .. rst-class:: classref-method
  709. :ref:`bool<class_bool>` **store_float**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_float>`
  710. Stores a floating-point number as 32 bits in the file.
  711. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  712. .. rst-class:: classref-item-separator
  713. ----
  714. .. _class_FileAccess_method_store_half:
  715. .. rst-class:: classref-method
  716. :ref:`bool<class_bool>` **store_half**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_half>`
  717. Stores a half-precision floating-point number as 16 bits in the file.
  718. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  719. .. rst-class:: classref-item-separator
  720. ----
  721. .. _class_FileAccess_method_store_line:
  722. .. rst-class:: classref-method
  723. :ref:`bool<class_bool>` **store_line**\ (\ line\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_line>`
  724. Stores ``line`` in the file followed by a newline character (``\n``), encoding the text as UTF-8.
  725. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  726. .. rst-class:: classref-item-separator
  727. ----
  728. .. _class_FileAccess_method_store_pascal_string:
  729. .. rst-class:: classref-method
  730. :ref:`bool<class_bool>` **store_pascal_string**\ (\ string\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_pascal_string>`
  731. 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).
  732. Text will be encoded as UTF-8.
  733. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  734. .. rst-class:: classref-item-separator
  735. ----
  736. .. _class_FileAccess_method_store_real:
  737. .. rst-class:: classref-method
  738. :ref:`bool<class_bool>` **store_real**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_real>`
  739. Stores a floating-point number in the file.
  740. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  741. .. rst-class:: classref-item-separator
  742. ----
  743. .. _class_FileAccess_method_store_string:
  744. .. rst-class:: classref-method
  745. :ref:`bool<class_bool>` **store_string**\ (\ string\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_string>`
  746. Stores ``string`` in the file without a newline character (``\n``), encoding the text as UTF-8.
  747. \ **Note:** This method is intended to be used to write text files. The string is stored as a UTF-8 encoded buffer without string length or terminating zero, which means that it can't be loaded back easily. If you want to store a retrievable string in a binary file, consider using :ref:`store_pascal_string()<class_FileAccess_method_store_pascal_string>` instead. For retrieving strings from a text file, you can use ``get_buffer(length).get_string_from_utf8()`` (if you know the length) or :ref:`get_as_text()<class_FileAccess_method_get_as_text>`.
  748. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  749. .. rst-class:: classref-item-separator
  750. ----
  751. .. _class_FileAccess_method_store_var:
  752. .. rst-class:: classref-method
  753. :ref:`bool<class_bool>` **store_var**\ (\ value\: :ref:`Variant<class_Variant>`, full_objects\: :ref:`bool<class_bool>` = false\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_var>`
  754. Stores any Variant value in the file. If ``full_objects`` is ``true``, encoding objects is allowed (and can potentially include code).
  755. Internally, this uses the same encoding mechanism as the :ref:`@GlobalScope.var_to_bytes()<class_@GlobalScope_method_var_to_bytes>` method.
  756. \ **Note:** Not all properties are included. Only properties that are configured with the :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>` flag set will be serialized. You can add a new usage flag to a property by overriding the :ref:`Object._get_property_list()<class_Object_private_method__get_property_list>` method in your class. You can also check how property usage is configured by calling :ref:`Object._get_property_list()<class_Object_private_method__get_property_list>`. See :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>` for the possible usage flags.
  757. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  758. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  759. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  760. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  761. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  762. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  763. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  764. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  765. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  766. .. |void| replace:: :abbr:`void (No return value.)`