class_fileaccess.rst 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  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 has its own file cursor, which is the position in bytes in the file where the next read/write operation will occur. Functions such as :ref:`get_8()<class_FileAccess_method_get_8>`, :ref:`get_16()<class_FileAccess_method_get_16>`, :ref:`store_8()<class_FileAccess_method_store_8>`, and :ref:`store_16()<class_FileAccess_method_store_16>` will move the file cursor forward by the number of bytes read/written. The file cursor can be moved to a specific position using :ref:`seek()<class_FileAccess_method_seek>` or :ref:`seek_end()<class_FileAccess_method_seek_end>`, and its position can be retrieved using :ref:`get_position()<class_FileAccess_method_get_position>`.
  38. 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.
  39. \ **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``).
  40. \ **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.
  41. .. rst-class:: classref-introduction-group
  42. Tutorials
  43. ---------
  44. - :doc:`File system <../tutorials/scripting/filesystem>`
  45. - :doc:`Runtime file loading and saving <../tutorials/io/runtime_file_loading_and_saving>`
  46. - :doc:`Binary serialization API <../tutorials/io/binary_serialization_api>`
  47. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/2755>`__
  48. .. rst-class:: classref-reftable-group
  49. Properties
  50. ----------
  51. .. table::
  52. :widths: auto
  53. +-------------------------+---------------------------------------------------------+
  54. | :ref:`bool<class_bool>` | :ref:`big_endian<class_FileAccess_property_big_endian>` |
  55. +-------------------------+---------------------------------------------------------+
  56. .. rst-class:: classref-reftable-group
  57. Methods
  58. -------
  59. .. table::
  60. :widths: auto
  61. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | |void| | :ref:`close<class_FileAccess_method_close>`\ (\ ) |
  63. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :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| |
  65. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`bool<class_bool>` | :ref:`eof_reached<class_FileAccess_method_eof_reached>`\ (\ ) |const| |
  67. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`bool<class_bool>` | :ref:`file_exists<class_FileAccess_method_file_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  69. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | |void| | :ref:`flush<class_FileAccess_method_flush>`\ (\ ) |
  71. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`get_8<class_FileAccess_method_get_8>`\ (\ ) |const| |
  73. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`int<class_int>` | :ref:`get_16<class_FileAccess_method_get_16>`\ (\ ) |const| |
  75. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`int<class_int>` | :ref:`get_32<class_FileAccess_method_get_32>`\ (\ ) |const| |
  77. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`int<class_int>` | :ref:`get_64<class_FileAccess_method_get_64>`\ (\ ) |const| |
  79. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`int<class_int>` | :ref:`get_access_time<class_FileAccess_method_get_access_time>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  81. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`String<class_String>` | :ref:`get_as_text<class_FileAccess_method_get_as_text>`\ (\ ) |const| |
  83. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_buffer<class_FileAccess_method_get_buffer>`\ (\ length\: :ref:`int<class_int>`\ ) |const| |
  85. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_csv_line<class_FileAccess_method_get_csv_line>`\ (\ delim\: :ref:`String<class_String>` = ","\ ) |const| |
  87. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`float<class_float>` | :ref:`get_double<class_FileAccess_method_get_double>`\ (\ ) |const| |
  89. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_error<class_FileAccess_method_get_error>`\ (\ ) |const| |
  91. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_file_as_bytes<class_FileAccess_method_get_file_as_bytes>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  93. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`String<class_String>` | :ref:`get_file_as_string<class_FileAccess_method_get_file_as_string>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  95. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`float<class_float>` | :ref:`get_float<class_FileAccess_method_get_float>`\ (\ ) |const| |
  97. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`float<class_float>` | :ref:`get_half<class_FileAccess_method_get_half>`\ (\ ) |const| |
  99. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`get_hidden_attribute<class_FileAccess_method_get_hidden_attribute>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  101. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`int<class_int>` | :ref:`get_length<class_FileAccess_method_get_length>`\ (\ ) |const| |
  103. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`String<class_String>` | :ref:`get_line<class_FileAccess_method_get_line>`\ (\ ) |const| |
  105. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`String<class_String>` | :ref:`get_md5<class_FileAccess_method_get_md5>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  107. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`int<class_int>` | :ref:`get_modified_time<class_FileAccess_method_get_modified_time>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  109. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_open_error<class_FileAccess_method_get_open_error>`\ (\ ) |static| |
  111. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`String<class_String>` | :ref:`get_pascal_string<class_FileAccess_method_get_pascal_string>`\ (\ ) |
  113. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`String<class_String>` | :ref:`get_path<class_FileAccess_method_get_path>`\ (\ ) |const| |
  115. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`String<class_String>` | :ref:`get_path_absolute<class_FileAccess_method_get_path_absolute>`\ (\ ) |const| |
  117. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`int<class_int>` | :ref:`get_position<class_FileAccess_method_get_position>`\ (\ ) |const| |
  119. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`bool<class_bool>` | :ref:`get_read_only_attribute<class_FileAccess_method_get_read_only_attribute>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  121. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`float<class_float>` | :ref:`get_real<class_FileAccess_method_get_real>`\ (\ ) |const| |
  123. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`String<class_String>` | :ref:`get_sha256<class_FileAccess_method_get_sha256>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  125. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`int<class_int>` | :ref:`get_size<class_FileAccess_method_get_size>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  127. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\] | :ref:`get_unix_permissions<class_FileAccess_method_get_unix_permissions>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
  129. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_FileAccess_method_get_var>`\ (\ allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| |
  131. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`bool<class_bool>` | :ref:`is_open<class_FileAccess_method_is_open>`\ (\ ) |const| |
  133. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`FileAccess<class_FileAccess>` | :ref:`open<class_FileAccess_method_open>`\ (\ path\: :ref:`String<class_String>`, flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`\ ) |static| |
  135. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :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| |
  137. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :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| |
  139. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :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| |
  141. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`resize<class_FileAccess_method_resize>`\ (\ length\: :ref:`int<class_int>`\ ) |
  143. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | |void| | :ref:`seek<class_FileAccess_method_seek>`\ (\ position\: :ref:`int<class_int>`\ ) |
  145. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | |void| | :ref:`seek_end<class_FileAccess_method_seek_end>`\ (\ position\: :ref:`int<class_int>` = 0\ ) |
  147. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :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| |
  149. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :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| |
  151. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :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| |
  153. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`bool<class_bool>` | :ref:`store_8<class_FileAccess_method_store_8>`\ (\ value\: :ref:`int<class_int>`\ ) |
  155. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`bool<class_bool>` | :ref:`store_16<class_FileAccess_method_store_16>`\ (\ value\: :ref:`int<class_int>`\ ) |
  157. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`bool<class_bool>` | :ref:`store_32<class_FileAccess_method_store_32>`\ (\ value\: :ref:`int<class_int>`\ ) |
  159. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`bool<class_bool>` | :ref:`store_64<class_FileAccess_method_store_64>`\ (\ value\: :ref:`int<class_int>`\ ) |
  161. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`bool<class_bool>` | :ref:`store_buffer<class_FileAccess_method_store_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
  163. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`bool<class_bool>` | :ref:`store_csv_line<class_FileAccess_method_store_csv_line>`\ (\ values\: :ref:`PackedStringArray<class_PackedStringArray>`, delim\: :ref:`String<class_String>` = ","\ ) |
  165. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`bool<class_bool>` | :ref:`store_double<class_FileAccess_method_store_double>`\ (\ value\: :ref:`float<class_float>`\ ) |
  167. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`bool<class_bool>` | :ref:`store_float<class_FileAccess_method_store_float>`\ (\ value\: :ref:`float<class_float>`\ ) |
  169. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`bool<class_bool>` | :ref:`store_half<class_FileAccess_method_store_half>`\ (\ value\: :ref:`float<class_float>`\ ) |
  171. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`bool<class_bool>` | :ref:`store_line<class_FileAccess_method_store_line>`\ (\ line\: :ref:`String<class_String>`\ ) |
  173. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`bool<class_bool>` | :ref:`store_pascal_string<class_FileAccess_method_store_pascal_string>`\ (\ string\: :ref:`String<class_String>`\ ) |
  175. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  176. | :ref:`bool<class_bool>` | :ref:`store_real<class_FileAccess_method_store_real>`\ (\ value\: :ref:`float<class_float>`\ ) |
  177. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  178. | :ref:`bool<class_bool>` | :ref:`store_string<class_FileAccess_method_store_string>`\ (\ string\: :ref:`String<class_String>`\ ) |
  179. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  180. | :ref:`bool<class_bool>` | :ref:`store_var<class_FileAccess_method_store_var>`\ (\ value\: :ref:`Variant<class_Variant>`, full_objects\: :ref:`bool<class_bool>` = false\ ) |
  181. +-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  182. .. rst-class:: classref-section-separator
  183. ----
  184. .. rst-class:: classref-descriptions-group
  185. Enumerations
  186. ------------
  187. .. _enum_FileAccess_ModeFlags:
  188. .. rst-class:: classref-enumeration
  189. enum **ModeFlags**: :ref:`๐Ÿ”—<enum_FileAccess_ModeFlags>`
  190. .. _class_FileAccess_constant_READ:
  191. .. rst-class:: classref-enumeration-constant
  192. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **READ** = ``1``
  193. Opens the file for read operations. The file cursor is positioned at the beginning of the file.
  194. .. _class_FileAccess_constant_WRITE:
  195. .. rst-class:: classref-enumeration-constant
  196. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **WRITE** = ``2``
  197. Opens the file for write operations. If the file exists, it is truncated to zero length and its contents are cleared. Otherwise, it is created.
  198. \ **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>`.
  199. .. _class_FileAccess_constant_READ_WRITE:
  200. .. rst-class:: classref-enumeration-constant
  201. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **READ_WRITE** = ``3``
  202. Opens the file for read and write operations. Does not truncate the file. The file cursor is positioned at the beginning of the file.
  203. .. _class_FileAccess_constant_WRITE_READ:
  204. .. rst-class:: classref-enumeration-constant
  205. :ref:`ModeFlags<enum_FileAccess_ModeFlags>` **WRITE_READ** = ``7``
  206. Opens the file for read and write operations. If the file exists, it is truncated to zero length and its contents are cleared. Otherwise, it is created. The file cursor is positioned at the beginning of the file.
  207. \ **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>`.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _enum_FileAccess_CompressionMode:
  211. .. rst-class:: classref-enumeration
  212. enum **CompressionMode**: :ref:`๐Ÿ”—<enum_FileAccess_CompressionMode>`
  213. .. _class_FileAccess_constant_COMPRESSION_FASTLZ:
  214. .. rst-class:: classref-enumeration-constant
  215. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_FASTLZ** = ``0``
  216. Uses the `FastLZ <https://fastlz.org/>`__ compression method.
  217. .. _class_FileAccess_constant_COMPRESSION_DEFLATE:
  218. .. rst-class:: classref-enumeration-constant
  219. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_DEFLATE** = ``1``
  220. Uses the `DEFLATE <https://en.wikipedia.org/wiki/DEFLATE>`__ compression method.
  221. .. _class_FileAccess_constant_COMPRESSION_ZSTD:
  222. .. rst-class:: classref-enumeration-constant
  223. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_ZSTD** = ``2``
  224. Uses the `Zstandard <https://facebook.github.io/zstd/>`__ compression method.
  225. .. _class_FileAccess_constant_COMPRESSION_GZIP:
  226. .. rst-class:: classref-enumeration-constant
  227. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_GZIP** = ``3``
  228. Uses the `gzip <https://www.gzip.org/>`__ compression method.
  229. .. _class_FileAccess_constant_COMPRESSION_BROTLI:
  230. .. rst-class:: classref-enumeration-constant
  231. :ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_BROTLI** = ``4``
  232. Uses the `brotli <https://github.com/google/brotli>`__ compression method (only decompression is supported).
  233. .. rst-class:: classref-item-separator
  234. ----
  235. .. _enum_FileAccess_UnixPermissionFlags:
  236. .. rst-class:: classref-enumeration
  237. flags **UnixPermissionFlags**: :ref:`๐Ÿ”—<enum_FileAccess_UnixPermissionFlags>`
  238. .. _class_FileAccess_constant_UNIX_READ_OWNER:
  239. .. rst-class:: classref-enumeration-constant
  240. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_OWNER** = ``256``
  241. Read for owner bit.
  242. .. _class_FileAccess_constant_UNIX_WRITE_OWNER:
  243. .. rst-class:: classref-enumeration-constant
  244. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_OWNER** = ``128``
  245. Write for owner bit.
  246. .. _class_FileAccess_constant_UNIX_EXECUTE_OWNER:
  247. .. rst-class:: classref-enumeration-constant
  248. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_OWNER** = ``64``
  249. Execute for owner bit.
  250. .. _class_FileAccess_constant_UNIX_READ_GROUP:
  251. .. rst-class:: classref-enumeration-constant
  252. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_GROUP** = ``32``
  253. Read for group bit.
  254. .. _class_FileAccess_constant_UNIX_WRITE_GROUP:
  255. .. rst-class:: classref-enumeration-constant
  256. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_GROUP** = ``16``
  257. Write for group bit.
  258. .. _class_FileAccess_constant_UNIX_EXECUTE_GROUP:
  259. .. rst-class:: classref-enumeration-constant
  260. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_GROUP** = ``8``
  261. Execute for group bit.
  262. .. _class_FileAccess_constant_UNIX_READ_OTHER:
  263. .. rst-class:: classref-enumeration-constant
  264. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_OTHER** = ``4``
  265. Read for other bit.
  266. .. _class_FileAccess_constant_UNIX_WRITE_OTHER:
  267. .. rst-class:: classref-enumeration-constant
  268. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_OTHER** = ``2``
  269. Write for other bit.
  270. .. _class_FileAccess_constant_UNIX_EXECUTE_OTHER:
  271. .. rst-class:: classref-enumeration-constant
  272. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_OTHER** = ``1``
  273. Execute for other bit.
  274. .. _class_FileAccess_constant_UNIX_SET_USER_ID:
  275. .. rst-class:: classref-enumeration-constant
  276. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_SET_USER_ID** = ``2048``
  277. Set user id on execution bit.
  278. .. _class_FileAccess_constant_UNIX_SET_GROUP_ID:
  279. .. rst-class:: classref-enumeration-constant
  280. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_SET_GROUP_ID** = ``1024``
  281. Set group id on execution bit.
  282. .. _class_FileAccess_constant_UNIX_RESTRICTED_DELETE:
  283. .. rst-class:: classref-enumeration-constant
  284. :ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_RESTRICTED_DELETE** = ``512``
  285. Restricted deletion (sticky) bit.
  286. .. rst-class:: classref-section-separator
  287. ----
  288. .. rst-class:: classref-descriptions-group
  289. Property Descriptions
  290. ---------------------
  291. .. _class_FileAccess_property_big_endian:
  292. .. rst-class:: classref-property
  293. :ref:`bool<class_bool>` **big_endian** :ref:`๐Ÿ”—<class_FileAccess_property_big_endian>`
  294. .. rst-class:: classref-property-setget
  295. - |void| **set_big_endian**\ (\ value\: :ref:`bool<class_bool>`\ )
  296. - :ref:`bool<class_bool>` **is_big_endian**\ (\ )
  297. 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.
  298. \ **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.
  299. .. rst-class:: classref-section-separator
  300. ----
  301. .. rst-class:: classref-descriptions-group
  302. Method Descriptions
  303. -------------------
  304. .. _class_FileAccess_method_close:
  305. .. rst-class:: classref-method
  306. |void| **close**\ (\ ) :ref:`๐Ÿ”—<class_FileAccess_method_close>`
  307. 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.
  308. \ **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.
  309. .. rst-class:: classref-item-separator
  310. ----
  311. .. _class_FileAccess_method_create_temp:
  312. .. rst-class:: classref-method
  313. :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>`
  314. Creates a temporary file. This file will be freed when the returned **FileAccess** is freed.
  315. If ``prefix`` is not empty, it will be prefixed to the file name, separated by a ``-``.
  316. If ``extension`` is not empty, it will be appended to the temporary file name.
  317. If ``keep`` is ``true``, the file is not deleted when the returned **FileAccess** is freed.
  318. 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.
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_FileAccess_method_eof_reached:
  322. .. rst-class:: classref-method
  323. :ref:`bool<class_bool>` **eof_reached**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_eof_reached>`
  324. Returns ``true`` if the file cursor has already read past the end of the file.
  325. \ **Note:** ``eof_reached() == false`` cannot be used to check whether there is more data available. To loop while there is more data available, use:
  326. .. tabs::
  327. .. code-tab:: gdscript
  328. while file.get_position() < file.get_length():
  329. # Read data
  330. .. code-tab:: csharp
  331. while (file.GetPosition() < file.GetLength())
  332. {
  333. // Read data
  334. }
  335. .. rst-class:: classref-item-separator
  336. ----
  337. .. _class_FileAccess_method_file_exists:
  338. .. rst-class:: classref-method
  339. :ref:`bool<class_bool>` **file_exists**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_file_exists>`
  340. Returns ``true`` if the file exists in the given path.
  341. \ **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.
  342. For a non-static, relative equivalent, use :ref:`DirAccess.file_exists()<class_DirAccess_method_file_exists>`.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_FileAccess_method_flush:
  346. .. rst-class:: classref-method
  347. |void| **flush**\ (\ ) :ref:`๐Ÿ”—<class_FileAccess_method_flush>`
  348. 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.
  349. \ **Note:** Only call :ref:`flush()<class_FileAccess_method_flush>` when you actually need it. Otherwise, it will decrease performance due to constant disk writes.
  350. .. rst-class:: classref-item-separator
  351. ----
  352. .. _class_FileAccess_method_get_8:
  353. .. rst-class:: classref-method
  354. :ref:`int<class_int>` **get_8**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_8>`
  355. Returns the next 8 bits from the file as an integer. This advances the file cursor by 1 byte. See :ref:`store_8()<class_FileAccess_method_store_8>` for details on what values can be stored and retrieved this way.
  356. .. rst-class:: classref-item-separator
  357. ----
  358. .. _class_FileAccess_method_get_16:
  359. .. rst-class:: classref-method
  360. :ref:`int<class_int>` **get_16**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_16>`
  361. Returns the next 16 bits from the file as an integer. This advances the file cursor by 2 bytes. See :ref:`store_16()<class_FileAccess_method_store_16>` for details on what values can be stored and retrieved this way.
  362. .. rst-class:: classref-item-separator
  363. ----
  364. .. _class_FileAccess_method_get_32:
  365. .. rst-class:: classref-method
  366. :ref:`int<class_int>` **get_32**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_32>`
  367. Returns the next 32 bits from the file as an integer. This advances the file cursor by 4 bytes. See :ref:`store_32()<class_FileAccess_method_store_32>` for details on what values can be stored and retrieved this way.
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_FileAccess_method_get_64:
  371. .. rst-class:: classref-method
  372. :ref:`int<class_int>` **get_64**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_64>`
  373. Returns the next 64 bits from the file as an integer. This advances the file cursor by 8 bytes. See :ref:`store_64()<class_FileAccess_method_store_64>` for details on what values can be stored and retrieved this way.
  374. .. rst-class:: classref-item-separator
  375. ----
  376. .. _class_FileAccess_method_get_access_time:
  377. .. rst-class:: classref-method
  378. :ref:`int<class_int>` **get_access_time**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_access_time>`
  379. 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.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_FileAccess_method_get_as_text:
  383. .. rst-class:: classref-method
  384. :ref:`String<class_String>` **get_as_text**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_as_text>`
  385. Returns the whole file as a :ref:`String<class_String>`. Text is interpreted as being UTF-8 encoded. This ignores the file cursor and does not affect it.
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_FileAccess_method_get_buffer:
  389. .. rst-class:: classref-method
  390. :ref:`PackedByteArray<class_PackedByteArray>` **get_buffer**\ (\ length\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_buffer>`
  391. Returns next ``length`` bytes of the file as a :ref:`PackedByteArray<class_PackedByteArray>`. This advances the file cursor by ``length`` bytes.
  392. .. rst-class:: classref-item-separator
  393. ----
  394. .. _class_FileAccess_method_get_csv_line:
  395. .. rst-class:: classref-method
  396. :ref:`PackedStringArray<class_PackedStringArray>` **get_csv_line**\ (\ delim\: :ref:`String<class_String>` = ","\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_csv_line>`
  397. 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.
  398. 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. This advances the file cursor to after the newline character at the end of the line.
  399. For example, the following CSV lines are valid and will be properly parsed as two strings each:
  400. .. code:: text
  401. Alice,"Hello, Bob!"
  402. Bob,Alice! What a surprise!
  403. Alice,"I thought you'd reply with ""Hello, world""."
  404. 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.
  405. .. rst-class:: classref-item-separator
  406. ----
  407. .. _class_FileAccess_method_get_double:
  408. .. rst-class:: classref-method
  409. :ref:`float<class_float>` **get_double**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_double>`
  410. Returns the next 64 bits from the file as a floating-point number. This advances the file cursor by 8 bytes.
  411. .. rst-class:: classref-item-separator
  412. ----
  413. .. _class_FileAccess_method_get_error:
  414. .. rst-class:: classref-method
  415. :ref:`Error<enum_@GlobalScope_Error>` **get_error**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_error>`
  416. Returns the last error that happened when trying to perform operations. Compare with the ``ERR_FILE_*`` constants from :ref:`Error<enum_@GlobalScope_Error>`.
  417. .. rst-class:: classref-item-separator
  418. ----
  419. .. _class_FileAccess_method_get_file_as_bytes:
  420. .. rst-class:: classref-method
  421. :ref:`PackedByteArray<class_PackedByteArray>` **get_file_as_bytes**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_file_as_bytes>`
  422. Returns the whole ``path`` file contents as a :ref:`PackedByteArray<class_PackedByteArray>` without any decoding.
  423. 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.
  424. .. rst-class:: classref-item-separator
  425. ----
  426. .. _class_FileAccess_method_get_file_as_string:
  427. .. rst-class:: classref-method
  428. :ref:`String<class_String>` **get_file_as_string**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_file_as_string>`
  429. Returns the whole ``path`` file contents as a :ref:`String<class_String>`. Text is interpreted as being UTF-8 encoded.
  430. 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.
  431. .. rst-class:: classref-item-separator
  432. ----
  433. .. _class_FileAccess_method_get_float:
  434. .. rst-class:: classref-method
  435. :ref:`float<class_float>` **get_float**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_float>`
  436. Returns the next 32 bits from the file as a floating-point number. This advances the file cursor by 4 bytes.
  437. .. rst-class:: classref-item-separator
  438. ----
  439. .. _class_FileAccess_method_get_half:
  440. .. rst-class:: classref-method
  441. :ref:`float<class_float>` **get_half**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_half>`
  442. Returns the next 16 bits from the file as a half-precision floating-point number. This advances the file cursor by 2 bytes.
  443. .. rst-class:: classref-item-separator
  444. ----
  445. .. _class_FileAccess_method_get_hidden_attribute:
  446. .. rst-class:: classref-method
  447. :ref:`bool<class_bool>` **get_hidden_attribute**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_hidden_attribute>`
  448. Returns ``true``, if file ``hidden`` attribute is set.
  449. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  450. .. rst-class:: classref-item-separator
  451. ----
  452. .. _class_FileAccess_method_get_length:
  453. .. rst-class:: classref-method
  454. :ref:`int<class_int>` **get_length**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_length>`
  455. Returns the size of the file in bytes. For a pipe, returns the number of bytes available for reading from the pipe.
  456. .. rst-class:: classref-item-separator
  457. ----
  458. .. _class_FileAccess_method_get_line:
  459. .. rst-class:: classref-method
  460. :ref:`String<class_String>` **get_line**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_line>`
  461. 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. This advances the file cursor to after the newline character at the end of the line.
  462. Text is interpreted as being UTF-8 encoded.
  463. .. rst-class:: classref-item-separator
  464. ----
  465. .. _class_FileAccess_method_get_md5:
  466. .. rst-class:: classref-method
  467. :ref:`String<class_String>` **get_md5**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_md5>`
  468. Returns an MD5 String representing the file at the given path or an empty :ref:`String<class_String>` on failure.
  469. .. rst-class:: classref-item-separator
  470. ----
  471. .. _class_FileAccess_method_get_modified_time:
  472. .. rst-class:: classref-method
  473. :ref:`int<class_int>` **get_modified_time**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_modified_time>`
  474. 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.
  475. .. rst-class:: classref-item-separator
  476. ----
  477. .. _class_FileAccess_method_get_open_error:
  478. .. rst-class:: classref-method
  479. :ref:`Error<enum_@GlobalScope_Error>` **get_open_error**\ (\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_open_error>`
  480. Returns the result of the last :ref:`open()<class_FileAccess_method_open>` call in the current thread.
  481. .. rst-class:: classref-item-separator
  482. ----
  483. .. _class_FileAccess_method_get_pascal_string:
  484. .. rst-class:: classref-method
  485. :ref:`String<class_String>` **get_pascal_string**\ (\ ) :ref:`๐Ÿ”—<class_FileAccess_method_get_pascal_string>`
  486. Returns a :ref:`String<class_String>` saved in Pascal format from the file, meaning that the length of the string is explicitly stored at the start. See :ref:`store_pascal_string()<class_FileAccess_method_store_pascal_string>`. This may include newline characters. The file cursor is advanced after the bytes read.
  487. Text is interpreted as being UTF-8 encoded.
  488. .. rst-class:: classref-item-separator
  489. ----
  490. .. _class_FileAccess_method_get_path:
  491. .. rst-class:: classref-method
  492. :ref:`String<class_String>` **get_path**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_path>`
  493. Returns the path as a :ref:`String<class_String>` for the current open file.
  494. .. rst-class:: classref-item-separator
  495. ----
  496. .. _class_FileAccess_method_get_path_absolute:
  497. .. rst-class:: classref-method
  498. :ref:`String<class_String>` **get_path_absolute**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_path_absolute>`
  499. Returns the absolute path as a :ref:`String<class_String>` for the current open file.
  500. .. rst-class:: classref-item-separator
  501. ----
  502. .. _class_FileAccess_method_get_position:
  503. .. rst-class:: classref-method
  504. :ref:`int<class_int>` **get_position**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_position>`
  505. Returns the file cursor's position in bytes from the beginning of the file. This is the file reading/writing cursor set by :ref:`seek()<class_FileAccess_method_seek>` or :ref:`seek_end()<class_FileAccess_method_seek_end>` and advanced by read/write operations.
  506. .. rst-class:: classref-item-separator
  507. ----
  508. .. _class_FileAccess_method_get_read_only_attribute:
  509. .. rst-class:: classref-method
  510. :ref:`bool<class_bool>` **get_read_only_attribute**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_read_only_attribute>`
  511. Returns ``true``, if file ``read only`` attribute is set.
  512. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  513. .. rst-class:: classref-item-separator
  514. ----
  515. .. _class_FileAccess_method_get_real:
  516. .. rst-class:: classref-method
  517. :ref:`float<class_float>` **get_real**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_real>`
  518. Returns the next bits from the file as a floating-point number. This advances the file cursor by either 4 or 8 bytes, depending on the precision used by the Godot build that saved the file.
  519. If the file was saved by a Godot build compiled with the ``precision=single`` option (the default), the number of read bits for that file is 32. Otherwise, if compiled with the ``precision=double`` option, the number of read bits is 64.
  520. .. rst-class:: classref-item-separator
  521. ----
  522. .. _class_FileAccess_method_get_sha256:
  523. .. rst-class:: classref-method
  524. :ref:`String<class_String>` **get_sha256**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_sha256>`
  525. Returns an SHA-256 :ref:`String<class_String>` representing the file at the given path or an empty :ref:`String<class_String>` on failure.
  526. .. rst-class:: classref-item-separator
  527. ----
  528. .. _class_FileAccess_method_get_size:
  529. .. rst-class:: classref-method
  530. :ref:`int<class_int>` **get_size**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_size>`
  531. Returns file size in bytes, or ``-1`` on error.
  532. .. rst-class:: classref-item-separator
  533. ----
  534. .. _class_FileAccess_method_get_unix_permissions:
  535. .. rst-class:: classref-method
  536. |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\] **get_unix_permissions**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_get_unix_permissions>`
  537. Returns file UNIX permissions.
  538. \ **Note:** This method is implemented on iOS, Linux/BSD, and macOS.
  539. .. rst-class:: classref-item-separator
  540. ----
  541. .. _class_FileAccess_method_get_var:
  542. .. rst-class:: classref-method
  543. :ref:`Variant<class_Variant>` **get_var**\ (\ allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_get_var>`
  544. Returns the next :ref:`Variant<class_Variant>` value from the file. If ``allow_objects`` is ``true``, decoding objects is allowed. This advances the file cursor by the number of bytes read.
  545. Internally, this uses the same decoding mechanism as the :ref:`@GlobalScope.bytes_to_var()<class_@GlobalScope_method_bytes_to_var>` method, as described in the :doc:`Binary serialization API <../tutorials/io/binary_serialization_api>` documentation.
  546. \ **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.
  547. .. rst-class:: classref-item-separator
  548. ----
  549. .. _class_FileAccess_method_is_open:
  550. .. rst-class:: classref-method
  551. :ref:`bool<class_bool>` **is_open**\ (\ ) |const| :ref:`๐Ÿ”—<class_FileAccess_method_is_open>`
  552. Returns ``true`` if the file is currently opened.
  553. .. rst-class:: classref-item-separator
  554. ----
  555. .. _class_FileAccess_method_open:
  556. .. rst-class:: classref-method
  557. :ref:`FileAccess<class_FileAccess>` **open**\ (\ path\: :ref:`String<class_String>`, flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`\ ) |static| :ref:`๐Ÿ”—<class_FileAccess_method_open>`
  558. Creates a new **FileAccess** object and opens the file for writing or reading, depending on the flags.
  559. 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.
  560. .. rst-class:: classref-item-separator
  561. ----
  562. .. _class_FileAccess_method_open_compressed:
  563. .. rst-class:: classref-method
  564. :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>`
  565. Creates a new **FileAccess** object and opens a compressed file for reading or writing.
  566. \ **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.
  567. 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.
  568. .. rst-class:: classref-item-separator
  569. ----
  570. .. _class_FileAccess_method_open_encrypted:
  571. .. rst-class:: classref-method
  572. :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>`
  573. 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.
  574. \ **Note:** The provided key must be 32 bytes long.
  575. 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.
  576. .. rst-class:: classref-item-separator
  577. ----
  578. .. _class_FileAccess_method_open_encrypted_with_pass:
  579. .. rst-class:: classref-method
  580. :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>`
  581. 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.
  582. 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.
  583. .. rst-class:: classref-item-separator
  584. ----
  585. .. _class_FileAccess_method_resize:
  586. .. rst-class:: classref-method
  587. :ref:`Error<enum_@GlobalScope_Error>` **resize**\ (\ length\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_resize>`
  588. 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.
  589. .. rst-class:: classref-item-separator
  590. ----
  591. .. _class_FileAccess_method_seek:
  592. .. rst-class:: classref-method
  593. |void| **seek**\ (\ position\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_seek>`
  594. Changes the file reading/writing cursor to the specified position (in bytes from the beginning of the file). This changes the value returned by :ref:`get_position()<class_FileAccess_method_get_position>`.
  595. .. rst-class:: classref-item-separator
  596. ----
  597. .. _class_FileAccess_method_seek_end:
  598. .. rst-class:: classref-method
  599. |void| **seek_end**\ (\ position\: :ref:`int<class_int>` = 0\ ) :ref:`๐Ÿ”—<class_FileAccess_method_seek_end>`
  600. Changes the file reading/writing cursor to the specified position (in bytes from the end of the file). This changes the value returned by :ref:`get_position()<class_FileAccess_method_get_position>`.
  601. \ **Note:** This is an offset, so you should use negative numbers or the file cursor will be at the end of the file.
  602. .. rst-class:: classref-item-separator
  603. ----
  604. .. _class_FileAccess_method_set_hidden_attribute:
  605. .. rst-class:: classref-method
  606. :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>`
  607. Sets file **hidden** attribute.
  608. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  609. .. rst-class:: classref-item-separator
  610. ----
  611. .. _class_FileAccess_method_set_read_only_attribute:
  612. .. rst-class:: classref-method
  613. :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>`
  614. Sets file **read only** attribute.
  615. \ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
  616. .. rst-class:: classref-item-separator
  617. ----
  618. .. _class_FileAccess_method_set_unix_permissions:
  619. .. rst-class:: classref-method
  620. :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>`
  621. Sets file UNIX permissions.
  622. \ **Note:** This method is implemented on iOS, Linux/BSD, and macOS.
  623. .. rst-class:: classref-item-separator
  624. ----
  625. .. _class_FileAccess_method_store_8:
  626. .. rst-class:: classref-method
  627. :ref:`bool<class_bool>` **store_8**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_8>`
  628. Stores an integer as 8 bits in the file. This advances the file cursor by 1 byte. Returns ``true`` if the operation is successful.
  629. \ **Note:** The ``value`` should lie in the interval ``[0, 255]``. Any other value will overflow and wrap around.
  630. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  631. 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).
  632. .. rst-class:: classref-item-separator
  633. ----
  634. .. _class_FileAccess_method_store_16:
  635. .. rst-class:: classref-method
  636. :ref:`bool<class_bool>` **store_16**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_16>`
  637. Stores an integer as 16 bits in the file. This advances the file cursor by 2 bytes. Returns ``true`` if the operation is successful.
  638. \ **Note:** The ``value`` should lie in the interval ``[0, 2^16 - 1]``. Any other value will overflow and wrap around.
  639. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  640. 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:
  641. .. tabs::
  642. .. code-tab:: gdscript
  643. const MAX_15B = 1 << 15
  644. const MAX_16B = 1 << 16
  645. func unsigned16_to_signed(unsigned):
  646. return (unsigned + MAX_15B) % MAX_16B - MAX_15B
  647. func _ready():
  648. var f = FileAccess.open("user://file.dat", FileAccess.WRITE_READ)
  649. f.store_16(-42) # This wraps around and stores 65494 (2^16 - 42).
  650. f.store_16(121) # In bounds, will store 121.
  651. f.seek(0) # Go back to start to read the stored value.
  652. var read1 = f.get_16() # 65494
  653. var read2 = f.get_16() # 121
  654. var converted1 = unsigned16_to_signed(read1) # -42
  655. var converted2 = unsigned16_to_signed(read2) # 121
  656. .. code-tab:: csharp
  657. public override void _Ready()
  658. {
  659. using var f = FileAccess.Open("user://file.dat", FileAccess.ModeFlags.WriteRead);
  660. f.Store16(unchecked((ushort)-42)); // This wraps around and stores 65494 (2^16 - 42).
  661. f.Store16(121); // In bounds, will store 121.
  662. f.Seek(0); // Go back to start to read the stored value.
  663. ushort read1 = f.Get16(); // 65494
  664. ushort read2 = f.Get16(); // 121
  665. short converted1 = (short)read1; // -42
  666. short converted2 = (short)read2; // 121
  667. }
  668. .. rst-class:: classref-item-separator
  669. ----
  670. .. _class_FileAccess_method_store_32:
  671. .. rst-class:: classref-method
  672. :ref:`bool<class_bool>` **store_32**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_32>`
  673. Stores an integer as 32 bits in the file. This advances the file cursor by 4 bytes. Returns ``true`` if the operation is successful.
  674. \ **Note:** The ``value`` should lie in the interval ``[0, 2^32 - 1]``. Any other value will overflow and wrap around.
  675. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  676. 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).
  677. .. rst-class:: classref-item-separator
  678. ----
  679. .. _class_FileAccess_method_store_64:
  680. .. rst-class:: classref-method
  681. :ref:`bool<class_bool>` **store_64**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_64>`
  682. Stores an integer as 64 bits in the file. This advances the file cursor by 8 bytes. Returns ``true`` if the operation is successful.
  683. \ **Note:** The ``value`` must lie in the interval ``[-2^63, 2^63 - 1]`` (i.e. be a valid :ref:`int<class_int>` value).
  684. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  685. .. rst-class:: classref-item-separator
  686. ----
  687. .. _class_FileAccess_method_store_buffer:
  688. .. rst-class:: classref-method
  689. :ref:`bool<class_bool>` **store_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_buffer>`
  690. Stores the given array of bytes in the file. This advances the file cursor by the number of bytes written. Returns ``true`` if the operation is successful.
  691. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  692. .. rst-class:: classref-item-separator
  693. ----
  694. .. _class_FileAccess_method_store_csv_line:
  695. .. rst-class:: classref-method
  696. :ref:`bool<class_bool>` **store_csv_line**\ (\ values\: :ref:`PackedStringArray<class_PackedStringArray>`, delim\: :ref:`String<class_String>` = ","\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_csv_line>`
  697. 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.
  698. Text will be encoded as UTF-8. Returns ``true`` if the operation is successful.
  699. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  700. .. rst-class:: classref-item-separator
  701. ----
  702. .. _class_FileAccess_method_store_double:
  703. .. rst-class:: classref-method
  704. :ref:`bool<class_bool>` **store_double**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_double>`
  705. Stores a floating-point number as 64 bits in the file. This advances the file cursor by 8 bytes. Returns ``true`` if the operation is successful.
  706. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  707. .. rst-class:: classref-item-separator
  708. ----
  709. .. _class_FileAccess_method_store_float:
  710. .. rst-class:: classref-method
  711. :ref:`bool<class_bool>` **store_float**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_float>`
  712. Stores a floating-point number as 32 bits in the file. This advances the file cursor by 4 bytes. Returns ``true`` if the operation is successful.
  713. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  714. .. rst-class:: classref-item-separator
  715. ----
  716. .. _class_FileAccess_method_store_half:
  717. .. rst-class:: classref-method
  718. :ref:`bool<class_bool>` **store_half**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_half>`
  719. Stores a half-precision floating-point number as 16 bits in the file. This advances the file cursor by 2 bytes. Returns ``true`` if the operation is successful.
  720. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  721. .. rst-class:: classref-item-separator
  722. ----
  723. .. _class_FileAccess_method_store_line:
  724. .. rst-class:: classref-method
  725. :ref:`bool<class_bool>` **store_line**\ (\ line\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_line>`
  726. Stores ``line`` in the file followed by a newline character (``\n``), encoding the text as UTF-8. This advances the file cursor by the length of the line, after the newline character. The amount of bytes written depends on the UTF-8 encoded bytes, which may be different from :ref:`String.length()<class_String_method_length>` which counts the number of UTF-32 codepoints. Returns ``true`` if the operation is successful.
  727. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  728. .. rst-class:: classref-item-separator
  729. ----
  730. .. _class_FileAccess_method_store_pascal_string:
  731. .. rst-class:: classref-method
  732. :ref:`bool<class_bool>` **store_pascal_string**\ (\ string\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_pascal_string>`
  733. 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). Text will be encoded as UTF-8. This advances the file cursor by the number of bytes written depending on the UTF-8 encoded bytes, which may be different from :ref:`String.length()<class_String_method_length>` which counts the number of UTF-32 codepoints. Returns ``true`` if the operation is successful.
  734. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  735. .. rst-class:: classref-item-separator
  736. ----
  737. .. _class_FileAccess_method_store_real:
  738. .. rst-class:: classref-method
  739. :ref:`bool<class_bool>` **store_real**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_real>`
  740. Stores a floating-point number in the file. This advances the file cursor by either 4 or 8 bytes, depending on the precision used by the current Godot build.
  741. If using a Godot build compiled with the ``precision=single`` option (the default), this method will save a 32-bit float. Otherwise, if compiled with the ``precision=double`` option, this will save a 64-bit float. Returns ``true`` if the operation is successful.
  742. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  743. .. rst-class:: classref-item-separator
  744. ----
  745. .. _class_FileAccess_method_store_string:
  746. .. rst-class:: classref-method
  747. :ref:`bool<class_bool>` **store_string**\ (\ string\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_string>`
  748. Stores ``string`` in the file without a newline character (``\n``), encoding the text as UTF-8. This advances the file cursor by the length of the string in UTF-8 encoded bytes, which may be different from :ref:`String.length()<class_String_method_length>` which counts the number of UTF-32 codepoints. Returns ``true`` if the operation is successful.
  749. \ **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>`.
  750. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  751. .. rst-class:: classref-item-separator
  752. ----
  753. .. _class_FileAccess_method_store_var:
  754. .. rst-class:: classref-method
  755. :ref:`bool<class_bool>` **store_var**\ (\ value\: :ref:`Variant<class_Variant>`, full_objects\: :ref:`bool<class_bool>` = false\ ) :ref:`๐Ÿ”—<class_FileAccess_method_store_var>`
  756. Stores any Variant value in the file. If ``full_objects`` is ``true``, encoding objects is allowed (and can potentially include code). This advances the file cursor by the number of bytes written. Returns ``true`` if the operation is successful.
  757. Internally, this uses the same encoding mechanism as the :ref:`@GlobalScope.var_to_bytes()<class_@GlobalScope_method_var_to_bytes>` method, as described in the :doc:`Binary serialization API <../tutorials/io/binary_serialization_api>` documentation.
  758. \ **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.
  759. \ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
  760. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  761. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  762. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  763. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  764. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  765. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  766. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  767. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  768. .. |void| replace:: :abbr:`void (No return value.)`