mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2026-01-04 10:09:56 +03:00
1488 lines
118 KiB
ReStructuredText
1488 lines
118 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_FileAccess:
|
||
|
||
FileAccess
|
||
==========
|
||
|
||
**Успадковує:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
Забезпечує методи читання файлів і написання операцій.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Опис
|
||
--------
|
||
|
||
Цей клас можна використовувати для постійного зберігання даних у файловій системі пристрою користувача та для читання з неї. Це корисно для зберігання даних збереження гри або файлів конфігурації гравця.
|
||
|
||
\ **Приклад:** Як записувати та читати з файлу. Файл з назвою ``"save_game.dat"`` буде збережено в папці даних користувача, як зазначено в документації :doc:`Шляхи до даних <../tutorials/io/data_paths>`:
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
func save_to_file(content):
|
||
var file = FileAccess.open("user://save_game.dat", FileAccess.WRITE)
|
||
file.store_string(content)
|
||
|
||
func load_from_file():
|
||
var file = FileAccess.open("user://save_game.dat", FileAccess.READ)
|
||
var content = file.get_as_text()
|
||
return content
|
||
|
||
.. code-tab:: csharp
|
||
|
||
public void SaveToFile(string content)
|
||
{
|
||
using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Write);
|
||
file.StoreString(content);
|
||
}
|
||
|
||
public string LoadFromFile()
|
||
{
|
||
using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Read);
|
||
string content = file.GetAsText();
|
||
return content;
|
||
}
|
||
|
||
|
||
|
||
Екземпляр **FileAccess** має власний файловий курсор, який є позицією в байтах у файлі, де відбудеться наступна операція читання/запису. Такі функції, як :ref:`get_8()<class_FileAccess_method_get_8>`, :ref:`get_16()<class_FileAccess_method_get_16>`, :ref:`store_8()<class_FileAccess_method_store_8>` та :ref:`store_16()<class_FileAccess_method_store_16>`, перемістять файловий курсор вперед на кількість прочитаних/записаних байтів. Файловий курсор можна перемістити в певну позицію за допомогою :ref:`seek()<class_FileAccess_method_seek>` або :ref:`seek_end()<class_FileAccess_method_seek_end>`, а його позицію можна отримати за допомогою :ref:`get_position()<class_FileAccess_method_get_position>`.
|
||
|
||
Екземпляр **FileAccess** закриє свій файл, коли екземпляр звільняється. Оскільки він успадковує :ref:`RefCounted<class_RefCounted>`, це відбувається автоматично, коли він більше не використовується. Для його ранішого закриття можна викликати :ref:`close()<class_FileAccess_method_close>`. У C# посилання потрібно видалити вручну, що можна зробити за допомогою оператора ``using`` або безпосередньо викликом методу ``Dispose``.
|
||
|
||
\ **Примітка:** Щоб отримати доступ до ресурсів проекту після експорту, рекомендується використовувати :ref:`ResourceLoader<class_ResourceLoader>` замість **FileAccess**, оскільки деякі файли конвертуються у формати, специфічні для рушія, і їхні оригінальні вихідні файли можуть бути відсутні в експортованому пакеті PCK. Якщо ви використовуєте **FileAccess**, переконайтеся, що файл включено до експорту, змінивши його режим імпорту на **Зберегти файл (експортовано як є)** у панелі імпорту, або, для файлів, для яких ця опція недоступна, змініть фільтр експорту без ресурсів у діалоговому вікні експорту, щоб включити розширення файлу (наприклад, ``*.txt``).
|
||
|
||
\ **Примітка:** Файли автоматично закриваються лише тоді, коли процес завершується «звичайним» чином (наприклад, натисканням кнопки закриття менеджера вікон або натисканням :kbd:`Alt + F4`). Якщо ви зупините виконання проекту натисканням :kbd:`F8` під час його роботи, файл не буде закрито, оскільки ігровий процес буде завершено. Ви можете обійти це, викликаючи :ref:`flush()<class_FileAccess_method_flush>` через регулярні проміжки часу.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Посібники
|
||
------------------
|
||
|
||
- :doc:`Файлова система <../tutorials/scripting/filesystem>`
|
||
|
||
- :doc:`Завантаження та збереження файлів під час виконання <../tutorials/io/runtime_file_loading_and_saving>`
|
||
|
||
- :doc:`API бінарної серіалізації <../tutorials/io/binary_serialization_api>`
|
||
|
||
- `Демонстрація 3D вокселів <https://godotengine.org/asset-library/asset/2755>`__
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Властивості
|
||
----------------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------+---------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`big_endian<class_FileAccess_property_big_endian>` |
|
||
+-------------------------+---------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Методи
|
||
------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`close<class_FileAccess_method_close>`\ (\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`eof_reached<class_FileAccess_method_eof_reached>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`file_exists<class_FileAccess_method_file_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`flush<class_FileAccess_method_flush>`\ (\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_8<class_FileAccess_method_get_8>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_16<class_FileAccess_method_get_16>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_32<class_FileAccess_method_get_32>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_64<class_FileAccess_method_get_64>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_access_time<class_FileAccess_method_get_access_time>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_as_text<class_FileAccess_method_get_as_text>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_buffer<class_FileAccess_method_get_buffer>`\ (\ length\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_csv_line<class_FileAccess_method_get_csv_line>`\ (\ delim\: :ref:`String<class_String>` = ","\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_double<class_FileAccess_method_get_double>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_error<class_FileAccess_method_get_error>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_extended_attribute<class_FileAccess_method_get_extended_attribute>`\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_extended_attribute_string<class_FileAccess_method_get_extended_attribute_string>`\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_extended_attributes_list<class_FileAccess_method_get_extended_attributes_list>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_file_as_bytes<class_FileAccess_method_get_file_as_bytes>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_file_as_string<class_FileAccess_method_get_file_as_string>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_float<class_FileAccess_method_get_float>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_half<class_FileAccess_method_get_half>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`get_hidden_attribute<class_FileAccess_method_get_hidden_attribute>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_length<class_FileAccess_method_get_length>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_line<class_FileAccess_method_get_line>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_md5<class_FileAccess_method_get_md5>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_modified_time<class_FileAccess_method_get_modified_time>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_open_error<class_FileAccess_method_get_open_error>`\ (\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_pascal_string<class_FileAccess_method_get_pascal_string>`\ (\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_path<class_FileAccess_method_get_path>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_path_absolute<class_FileAccess_method_get_path_absolute>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_position<class_FileAccess_method_get_position>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`get_read_only_attribute<class_FileAccess_method_get_read_only_attribute>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_real<class_FileAccess_method_get_real>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_sha256<class_FileAccess_method_get_sha256>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_size<class_FileAccess_method_get_size>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\] | :ref:`get_unix_permissions<class_FileAccess_method_get_unix_permissions>`\ (\ file\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_var<class_FileAccess_method_get_var>`\ (\ allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_open<class_FileAccess_method_is_open>`\ (\ ) |const| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`FileAccess<class_FileAccess>` | :ref:`open<class_FileAccess_method_open>`\ (\ path\: :ref:`String<class_String>`, flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove_extended_attribute<class_FileAccess_method_remove_extended_attribute>`\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`resize<class_FileAccess_method_resize>`\ (\ length\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`seek<class_FileAccess_method_seek>`\ (\ position\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`seek_end<class_FileAccess_method_seek_end>`\ (\ position\: :ref:`int<class_int>` = 0\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`set_extended_attribute<class_FileAccess_method_set_extended_attribute>`\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`, data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`set_extended_attribute_string<class_FileAccess_method_set_extended_attribute_string>`\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`, data\: :ref:`String<class_String>`\ ) |static| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_8<class_FileAccess_method_store_8>`\ (\ value\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_16<class_FileAccess_method_store_16>`\ (\ value\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_32<class_FileAccess_method_store_32>`\ (\ value\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_64<class_FileAccess_method_store_64>`\ (\ value\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_buffer<class_FileAccess_method_store_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_csv_line<class_FileAccess_method_store_csv_line>`\ (\ values\: :ref:`PackedStringArray<class_PackedStringArray>`, delim\: :ref:`String<class_String>` = ","\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_double<class_FileAccess_method_store_double>`\ (\ value\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_float<class_FileAccess_method_store_float>`\ (\ value\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_half<class_FileAccess_method_store_half>`\ (\ value\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_line<class_FileAccess_method_store_line>`\ (\ line\: :ref:`String<class_String>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_pascal_string<class_FileAccess_method_store_pascal_string>`\ (\ string\: :ref:`String<class_String>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_real<class_FileAccess_method_store_real>`\ (\ value\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_string<class_FileAccess_method_store_string>`\ (\ string\: :ref:`String<class_String>`\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`store_var<class_FileAccess_method_store_var>`\ (\ value\: :ref:`Variant<class_Variant>`, full_objects\: :ref:`bool<class_bool>` = false\ ) |
|
||
+-------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Переліки
|
||
----------------
|
||
|
||
.. _enum_FileAccess_ModeFlags:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **ModeFlags**: :ref:`🔗<enum_FileAccess_ModeFlags>`
|
||
|
||
.. _class_FileAccess_constant_READ:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ModeFlags<enum_FileAccess_ModeFlags>` **READ** = ``1``
|
||
|
||
Відкриває файл для операцій читання. Курсор файлу розташовується на початку файлу.
|
||
|
||
.. _class_FileAccess_constant_WRITE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ModeFlags<enum_FileAccess_ModeFlags>` **WRITE** = ``2``
|
||
|
||
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.
|
||
|
||
\ **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>`.
|
||
|
||
.. _class_FileAccess_constant_READ_WRITE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ModeFlags<enum_FileAccess_ModeFlags>` **READ_WRITE** = ``3``
|
||
|
||
Відкриває файл для операцій читання та запису. Не обрізає файл. Курсор файлу розташовується на початку файлу.
|
||
|
||
.. _class_FileAccess_constant_WRITE_READ:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ModeFlags<enum_FileAccess_ModeFlags>` **WRITE_READ** = ``7``
|
||
|
||
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.
|
||
|
||
\ **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>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _enum_FileAccess_CompressionMode:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **CompressionMode**: :ref:`🔗<enum_FileAccess_CompressionMode>`
|
||
|
||
.. _class_FileAccess_constant_COMPRESSION_FASTLZ:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_FASTLZ** = ``0``
|
||
|
||
Використовуйте метод стиснення `FastLZ <https://fastlz.org/>`__.
|
||
|
||
.. _class_FileAccess_constant_COMPRESSION_DEFLATE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_DEFLATE** = ``1``
|
||
|
||
Використовуйте метод стиснення `DEFLATE <https://en.wikipedia.org/wiki/DEFLATE>`__.
|
||
|
||
.. _class_FileAccess_constant_COMPRESSION_ZSTD:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_ZSTD** = ``2``
|
||
|
||
Використовуйте метод стиснення `Zstandard <https://facebook.github.io/zstd/>`__.
|
||
|
||
.. _class_FileAccess_constant_COMPRESSION_GZIP:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_GZIP** = ``3``
|
||
|
||
Використовуйте метод стиснення `gzip <https://www.gzip.org/>`__.
|
||
|
||
.. _class_FileAccess_constant_COMPRESSION_BROTLI:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CompressionMode<enum_FileAccess_CompressionMode>` **COMPRESSION_BROTLI** = ``4``
|
||
|
||
Використовуйте метод стиснення `brotli <https://github.com/google/brotli>`__ (тільки Decompression підтримується).
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _enum_FileAccess_UnixPermissionFlags:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
flags **UnixPermissionFlags**: :ref:`🔗<enum_FileAccess_UnixPermissionFlags>`
|
||
|
||
.. _class_FileAccess_constant_UNIX_READ_OWNER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_OWNER** = ``256``
|
||
|
||
Читати для власника трохи.
|
||
|
||
.. _class_FileAccess_constant_UNIX_WRITE_OWNER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_OWNER** = ``128``
|
||
|
||
Написати власника трохи.
|
||
|
||
.. _class_FileAccess_constant_UNIX_EXECUTE_OWNER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_OWNER** = ``64``
|
||
|
||
Виконання для власника біт.
|
||
|
||
.. _class_FileAccess_constant_UNIX_READ_GROUP:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_GROUP** = ``32``
|
||
|
||
Читати для групи біт.
|
||
|
||
.. _class_FileAccess_constant_UNIX_WRITE_GROUP:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_GROUP** = ``16``
|
||
|
||
Написати групу біт.
|
||
|
||
.. _class_FileAccess_constant_UNIX_EXECUTE_GROUP:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_GROUP** = ``8``
|
||
|
||
Виконання для групового біту.
|
||
|
||
.. _class_FileAccess_constant_UNIX_READ_OTHER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_READ_OTHER** = ``4``
|
||
|
||
Читати далі.
|
||
|
||
.. _class_FileAccess_constant_UNIX_WRITE_OTHER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_WRITE_OTHER** = ``2``
|
||
|
||
Записатися на інші біти.
|
||
|
||
.. _class_FileAccess_constant_UNIX_EXECUTE_OTHER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_EXECUTE_OTHER** = ``1``
|
||
|
||
Виконувати інші біти.
|
||
|
||
.. _class_FileAccess_constant_UNIX_SET_USER_ID:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_SET_USER_ID** = ``2048``
|
||
|
||
Встановити ідентифікатор користувача на виконання біт.
|
||
|
||
.. _class_FileAccess_constant_UNIX_SET_GROUP_ID:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_SET_GROUP_ID** = ``1024``
|
||
|
||
Встановити групу id на виконання біт.
|
||
|
||
.. _class_FileAccess_constant_UNIX_RESTRICTED_DELETE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>` **UNIX_RESTRICTED_DELETE** = ``512``
|
||
|
||
Обмеження видалення (пригарний) біт.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описи властивостей
|
||
------------------------------------
|
||
|
||
.. _class_FileAccess_property_big_endian:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`bool<class_bool>` **big_endian** :ref:`🔗<class_FileAccess_property_big_endian>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_big_endian**\ (\ value\: :ref:`bool<class_bool>`\ )
|
||
- :ref:`bool<class_bool>` **is_big_endian**\ (\ )
|
||
|
||
Якщо ``true``, файл читається з порядком байтів big-endian `endianness <https://en.wikipedia.org/wiki/Endianness>`__. Якщо ``false``, файл читається з порядком байтів little-endian. Якщо є сумніви, залиште це значення ``false``, оскільки більшість файлів записуються з порядком байтів little-endian.
|
||
|
||
\ **Примітка:** Це завжди скидається до системного порядка байтів, який є little-endian на всіх підтримуваних платформах, щоразу, коли ви відкриваєте файл. Тому ви повинні встановити :ref:`big_endian<class_FileAccess_property_big_endian>` *після* відкриття файлу, а не до.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описи методів
|
||
--------------------------
|
||
|
||
.. _class_FileAccess_method_close:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **close**\ (\ ) :ref:`🔗<class_FileAccess_method_close>`
|
||
|
||
Закриває поточний відкритий файл і запобігає подальшим операціям читання/запису. Використовуйте :ref:`flush()<class_FileAccess_method_flush>`, щоб зберегти дані на диску, не закриваючи файл.
|
||
|
||
\ **Примітка:** **FileAccess** автоматично закриється, коли його буде звільнено, що станеться, коли він виходить за межі області або коли йому буде призначено ``null``. У C# посилання має бути видалено після того, як ми закінчимо його використовувати, це можна зробити за допомогою оператора ``using`` або безпосереднього виклику методу ``Dispose``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_create_temp:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Створює тимчасовий файл. Цей файл буде звільнено, коли буде звільнено повернутий **FileAccess**.
|
||
|
||
Якщо ``prefix`` не порожній, він буде додано до імені файлу, розділеного ``-``.
|
||
|
||
Якщо ``extension`` не пусте, воно буде додано до імені тимчасового файлу.
|
||
|
||
Якщо ``keep`` має значення ``true``, файл не видаляється, коли звільняється повернутий **FileAccess**.
|
||
|
||
Повертає ``null``, якщо відкрити файл не вдалося. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>`, щоб перевірити помилку, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_eof_reached:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **eof_reached**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_eof_reached>`
|
||
|
||
Повертає ``true``, якщо файловий курсор уже прочитав кінець файлу.
|
||
|
||
\ **Примітка:** ``eof_reached() == false`` не можна використовувати для перевірки наявності додаткових даних. Для циклу, поки є більше доступних даних, використовуйте:
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
while file.get_position() < file.get_length():
|
||
# Читання даних
|
||
|
||
.. code-tab:: csharp
|
||
|
||
while (file.GetPosition() < file.GetLength())
|
||
{
|
||
// Читання даних
|
||
}
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_file_exists:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **file_exists**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_file_exists>`
|
||
|
||
Повертає ``true``, якщо файл існує в даній доріці.
|
||
|
||
\ **Примітка:** Багато типів ресурсів імпортуються (наприклад, текстури або звукові файли), а їх вихідний актив не буде включений до експортованої гри, оскільки використовується тільки імпортна версія. Див. :ref:`ResourceLoader.exists()<class_ResourceLoader_method_exists>` для альтернативного підходу, який бере на облік ресурсу.
|
||
|
||
Для нестатичного, відносного еквівалента, використання :ref:`DirAccess.file_exists()<class_DirAccess_method_file_exists>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_flush:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **flush**\ (\ ) :ref:`🔗<class_FileAccess_method_flush>`
|
||
|
||
Напишіть буфер файлів на диск. Промивання автоматично здійснюється при закритті файлу. Це означає, що вам не потрібно викликати :ref:`flush()<class_FileAccess_method_flush>` вручну перед закриттям файлу. На жаль, виклик :ref:`флуш()<class_FileAccess_method_флуш>` може бути використаний для забезпечення безпеки даних, навіть якщо проект не буде закритим гравіюванням.
|
||
|
||
\ **Примітка:** Тільки виклик :ref:`flush()<class_FileAccess_method_flush>`, коли вам дійсно потрібно. В іншому випадку це знизить продуктивність через постійні дискові записи.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_8:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_8**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_8>`
|
||
|
||
Повертає наступні 8 бітів з файлу як ціле число. Це переміщує курсор файлу на 1 байт. Див. :ref:`store_8()<class_FileAccess_method_store_8>` для отримання детальної інформації про те, які значення можна зберігати та отримувати таким чином.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_16:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_16**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_16>`
|
||
|
||
Повертає наступні 16 бітів з файлу як ціле число. Це переміщує курсор файлу на 2 байти. Див. :ref:`store_16()<class_FileAccess_method_store_16>` для отримання детальної інформації про те, які значення можна зберігати та отримувати таким чином.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_32:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_32**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_32>`
|
||
|
||
Повертає наступні 32 біти з файлу як ціле число. Це переміщує курсор файлу на 4 байти. Див. :ref:`store_32()<class_FileAccess_method_store_32>` для отримання детальної інформації про те, які значення можна зберігати та отримувати таким чином.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_64:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_64**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_64>`
|
||
|
||
Повертає наступні 64 біти з файлу як ціле число. Це переміщує курсор файлу на 8 байтів. Див. :ref:`store_64()<class_FileAccess_method_store_64>` для отримання детальної інформації про те, які значення можна зберігати та отримувати таким чином.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_access_time:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_access_time**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_access_time>`
|
||
|
||
Повертає час останнього доступу до ``file`` у форматі позначки часу Unix або ``0`` у разі помилки. Цю позначку часу Unix можна перетворити в інший формат за допомогою синглтона :ref:`Time<class_Time>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_as_text:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_as_text**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_as_text>`
|
||
|
||
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.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_buffer:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedByteArray<class_PackedByteArray>` **get_buffer**\ (\ length\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_FileAccess_method_get_buffer>`
|
||
|
||
Повертає наступні ``length`` байтів файлу як :ref:`PackedByteArray<class_PackedByteArray>`. Це переміщує курсор файлу на ``length`` байтів.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_csv_line:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedStringArray<class_PackedStringArray>` **get_csv_line**\ (\ delim\: :ref:`String<class_String>` = ","\ ) |const| :ref:`🔗<class_FileAccess_method_get_csv_line>`
|
||
|
||
Повертає наступне значення файлу у форматі CSV (значення, розділені комами). Ви можете передати інший роздільник ``delim``, відмінний від стандартного ``","`` (кома). Цей роздільник має бути довжиною один символ і не може бути подвійними лапками.
|
||
|
||
Текст інтерпретується як закодований UTF-8. Текстові значення повинні бути взяті в подвійні лапки, якщо вони містять роздільник. Подвійні лапки в текстовому значенні можна екранувати, подвоївши їх кількість. Це перемістить курсор файлу після символу нового рядка в кінці рядка.
|
||
|
||
Наприклад, наступні рядки CSV є дійсними та будуть правильно проаналізовані як два рядки кожен:
|
||
|
||
.. code:: text
|
||
|
||
Alice,"Hello, Bob!"
|
||
Bob,Alice! Який сюрприз!
|
||
Alice,"I thought you're reply ""Hello, world""."
|
||
|
||
Зверніть увагу, що другий рядок може пропускати лапки, оскільки він не містить роздільника. Однак, лапки *можна* використовувати, але без них це було написано лише для демонстрації. У третьому рядку для кожної лапки, яку потрібно інтерпретувати як таку, потрібно використовувати ``""``, а не кінець текстового значення.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_double:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_double**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_double>`
|
||
|
||
Повертає наступні 64 біти з файлу у вигляді числа з плаваючою комою. Це переміщує курсор файлу на 8 байтів.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_error:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **get_error**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_error>`
|
||
|
||
Повертаємо останню помилку, яка сталася при спробі виконання операцій. Порівняйте з ``ERR_FILE_*`` константи з :ref:`Error<enum_@GlobalScope_Error>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_extended_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedByteArray<class_PackedByteArray>` **get_extended_attribute**\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_extended_attribute>`
|
||
|
||
Reads the file extended attribute with name ``attribute_name`` as a byte array.
|
||
|
||
\ **Note:** This method is implemented on Linux, macOS, and Windows.
|
||
|
||
\ **Note:** Extended attributes support depends on the file system. Attributes will be lost when the file is moved between incompatible file systems.
|
||
|
||
\ **Note:** On Linux, only "user" namespace attributes are accessible, namespace prefix should not be included.
|
||
|
||
\ **Note:** On Windows, alternate data streams are used to store extended attributes.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_extended_attribute_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_extended_attribute_string**\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_extended_attribute_string>`
|
||
|
||
Reads the file extended attribute with name ``attribute_name`` as a UTF-8 encoded string.
|
||
|
||
\ **Note:** This method is implemented on Linux, macOS, and Windows.
|
||
|
||
\ **Note:** Extended attributes support depends on the file system. Attributes will be lost when the file is moved between incompatible file systems.
|
||
|
||
\ **Note:** On Linux, only "user" namespace attributes are accessible, namespace prefix should not be included.
|
||
|
||
\ **Note:** On Windows, alternate data streams are used to store extended attributes.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_extended_attributes_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedStringArray<class_PackedStringArray>` **get_extended_attributes_list**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_extended_attributes_list>`
|
||
|
||
Returns a list of file extended attributes.
|
||
|
||
\ **Note:** This method is implemented on Linux, macOS, and Windows.
|
||
|
||
\ **Note:** Extended attributes support depends on the file system. Attributes will be lost when the file is moved between incompatible file systems.
|
||
|
||
\ **Note:** On Linux, only "user" namespace attributes are accessible, namespace prefix should not be included.
|
||
|
||
\ **Note:** On Windows, alternate data streams are used to store extended attributes.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_file_as_bytes:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedByteArray<class_PackedByteArray>` **get_file_as_bytes**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_file_as_bytes>`
|
||
|
||
Повертаємо весь вміст файлу ``path`` як :ref:`PackedByteArray<class_PackedByteArray>` без будь-якого декодування.
|
||
|
||
Повертає порожній :ref:`PackedByteArray<class_PackedByteArray>`, якщо виникне помилка при відкритті файлу. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>` для перевірки помилки, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_file_as_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_file_as_string**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_file_as_string>`
|
||
|
||
Повертає весь ``path`` вміст файлу як :ref:`String<class_String>`. Текст інтерпретується як UTF-8 закодовано.
|
||
|
||
Повертає порожній :ref:`String<class_String>`, якщо виникла помилка при відкритті файлу. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>` для перевірки помилки, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_float:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_float**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_float>`
|
||
|
||
Повертає наступні 32 біти з файлу у вигляді числа з плаваючою комою. Це переміщує курсор файлу на 4 байти.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_half:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_half**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_half>`
|
||
|
||
Повертає наступні 16 бітів з файлу у вигляді числа з плаваючою комою половинної точності. Це переміщує курсор файлу на 2 байти.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_hidden_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **get_hidden_attribute**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_hidden_attribute>`
|
||
|
||
Returns ``true`` if the **hidden** attribute is set on the file at the given path.
|
||
|
||
\ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_length:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_length**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_length>`
|
||
|
||
Повертає розмір файлу в байтах. Для каналу повертає кількість байтів, доступних для читання з каналу.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_line:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_line**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_line>`
|
||
|
||
Повертає наступний рядок файлу як :ref:`String<class_String>`. Повернений рядок не містить символів нового рядка (``\n``) або повернення каретки (``\r``), але містить будь-які інші початкові або кінцеві пробіли. Це переміщує курсор файлу після символу нового рядка в кінці рядка.
|
||
|
||
Текст інтерпретується як закодований UTF-8.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_md5:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_md5**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_md5>`
|
||
|
||
Повертаємо вашу увагу на те, що файл на даній доріжці або порожній :ref:`String<class_String>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_modified_time:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_modified_time**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_modified_time>`
|
||
|
||
Повернувшись до останнього часу, файл ``file`` був модифікований у форматі Unix timestamp, або ``0`` на помилку. Цей Unix Timestamp може бути перетворений в інший формат, використовуючи одинтон :ref:`Time<class_Time>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_open_error:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **get_open_error**\ (\ ) |static| :ref:`🔗<class_FileAccess_method_get_open_error>`
|
||
|
||
Повертає результат останнього виклику :ref:`open()<class_FileAccess_method_open>` у поточному потоці.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_pascal_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_pascal_string**\ (\ ) :ref:`🔗<class_FileAccess_method_get_pascal_string>`
|
||
|
||
Повертає рядок :ref:`String<class_String>`, збережений у форматі Pascal з файлу, тобто довжина рядка явно зберігається на початку. Див. :ref:`store_pascal_string()<class_FileAccess_method_store_pascal_string>`. Це може включати символи нового рядка. Курсор файлу переміщується після прочитаних байтів.
|
||
|
||
Текст інтерпретується як закодований UTF-8.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_path:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_path**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_path>`
|
||
|
||
Повертає шлях як :ref:`String<class_String>` для поточного відкритого файлу.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_path_absolute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_path_absolute**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_path_absolute>`
|
||
|
||
Повертає абсолютний шлях як :ref:`String<class_String>` для поточного відкритого файлу.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_position:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_position**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_position>`
|
||
|
||
Повертає позицію курсора файлу в байтах від початку файлу. Це курсор читання/запису файлу, встановлений методом :ref:`seek()<class_FileAccess_method_seek>` або :ref:`seek_end()<class_FileAccess_method_seek_end>` та просуваний операціями читання/запису.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_read_only_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **get_read_only_attribute**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_read_only_attribute>`
|
||
|
||
Returns ``true`` if the **read only** attribute is set on the file at the given path.
|
||
|
||
\ **Note:** This method is implemented on iOS, BSD, macOS, and Windows.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_real:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_real**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_get_real>`
|
||
|
||
Повертає наступні біти з файлу як число з плаваючою комою. Це просуває курсор файлу на 4 або 8 байтів, залежно від точності, що використовується збіркою Godot, яка зберегла файл.
|
||
|
||
Якщо файл було збережено збіркою Godot, скомпільованою з опцією ``precision=single`` (за замовчуванням), кількість зчитаних бітів для цього файлу дорівнює 32. В іншому випадку, якщо компілюється з опцією ``precision=double``, кількість зчитаних бітів дорівнює 64.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_sha256:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_sha256**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_sha256>`
|
||
|
||
Повертає SHA-256 :ref:`String<class_String>`, що представляє файл на заданому шляху або порожній :ref:`String<class_String>` провал.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_size:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_size**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_size>`
|
||
|
||
Returns the size of the file at the given path, in bytes, or ``-1`` on error.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_unix_permissions:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|bitfield|\[:ref:`UnixPermissionFlags<enum_FileAccess_UnixPermissionFlags>`\] **get_unix_permissions**\ (\ file\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_get_unix_permissions>`
|
||
|
||
Returns the UNIX permissions of the file at the given path.
|
||
|
||
\ **Note:** This method is implemented on iOS, Linux/BSD, and macOS.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_get_var:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_var**\ (\ allow_objects\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_FileAccess_method_get_var>`
|
||
|
||
Повертає наступне значення :ref:`Variant<class_Variant>` з файлу. Якщо ``allow_objects`` має значення ``true``, декодування об'єктів дозволено. Це переміщує курсор файлу на кількість прочитаних байтів.
|
||
|
||
Внутрішньо цей метод використовує той самий механізм декодування, що й метод :ref:`@GlobalScope.bytes_to_var()<class_@GlobalScope_method_bytes_to_var>`, як описано в документації :doc:`Binary serialization API <../tutorials/io/binary_serialization_api>`.
|
||
|
||
\ **Попередження:** Десеріалізовані об'єкти можуть містити код, який виконується. Не використовуйте цю опцію, якщо серіалізований об'єкт походить з ненадійних джерел, щоб уникнути потенційних загроз безпеці, таких як віддалене виконання коду.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_is_open:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_open**\ (\ ) |const| :ref:`🔗<class_FileAccess_method_is_open>`
|
||
|
||
Повертаємо ``true``, якщо файл наразі відкритий.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_open:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`FileAccess<class_FileAccess>` **open**\ (\ path\: :ref:`String<class_String>`, flags\: :ref:`ModeFlags<enum_FileAccess_ModeFlags>`\ ) |static| :ref:`🔗<class_FileAccess_method_open>`
|
||
|
||
Створює новий об'єкт **FileAccess** і відкриває файл для написання або читання, в залежності від прапорів.
|
||
|
||
Повертає ``null``, якщо відкриття файлу не вдалося. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>` для перевірки помилки, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_open_compressed:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Створює новий об'єкт **FileAccess** і відкриває стиснений файл для читання або написання.
|
||
|
||
\ **Примітка:** :ref:`open_compressed()<class_FileAccess_method_open_compressed>` може лише читати файли, які були збережені Godot, не формати стиснення сторонніх сторін. Див. `Випуск GitHub #28999 <https://github.com/godotengine/godot/issues/28999>`__ для роботи.
|
||
|
||
Повертає ``null`` при відкритті файлу не вдалося. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>` для перевірки помилки, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_open_encrypted:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Створює новий об'єкт **FileAccess** і відкриває зашифрований файл в режимі запису або читання. Ви повинні пройти бінарний ключ для шифрування / розшифрування його.
|
||
|
||
\ **Примітка:** Надані ключі повинні бути 32 байти довгий.
|
||
|
||
Повертає ``null`` при відкритті файлу не вдалося. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>` для перевірки помилки, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_open_encrypted_with_pass:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Створює новий об'єкт **FileAccess** і відкриває зашифрований файл в режимі запису або читання. Ви повинні пройти пароль для шифрування / розшифрування його.
|
||
|
||
Повертає ``null``, якщо відкриття файлу не вдалося. Ви можете використовувати :ref:`get_open_error()<class_FileAccess_method_get_open_error>` для перевірки помилки, яка сталася.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_remove_extended_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **remove_extended_attribute**\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_remove_extended_attribute>`
|
||
|
||
Removes file extended attribute with name ``attribute_name``.
|
||
|
||
\ **Note:** This method is implemented on Linux, macOS, and Windows.
|
||
|
||
\ **Note:** Extended attributes support depends on the file system. Attributes will be lost when the file is moved between incompatible file systems.
|
||
|
||
\ **Note:** On Linux, only "user" namespace attributes are accessible, namespace prefix should not be included.
|
||
|
||
\ **Note:** On Windows, alternate data streams are used to store extended attributes.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_resize:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **resize**\ (\ length\: :ref:`int<class_int>`\ ) :ref:`🔗<class_FileAccess_method_resize>`
|
||
|
||
Змінити файл до вказаної довжини. Файл повинен бути відкритим у режимі, який дозволяє писати. Якщо файл розширено, наведено NUL символи. Якщо файл обрізається, всі дані з кінцевого файлу до початкової довжини файлу втрачені.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_seek:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **seek**\ (\ position\: :ref:`int<class_int>`\ ) :ref:`🔗<class_FileAccess_method_seek>`
|
||
|
||
Sets the file 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>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_seek_end:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **seek_end**\ (\ position\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_FileAccess_method_seek_end>`
|
||
|
||
Sets the file 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>`.
|
||
|
||
\ **Note:** This is an offset, so you should use negative numbers otherwise the file cursor will be at the end of the file.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_set_extended_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **set_extended_attribute**\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`, data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |static| :ref:`🔗<class_FileAccess_method_set_extended_attribute>`
|
||
|
||
Writes file extended attribute with name ``attribute_name`` as a byte array.
|
||
|
||
\ **Note:** This method is implemented on Linux, macOS, and Windows.
|
||
|
||
\ **Note:** Extended attributes support depends on the file system. Attributes will be lost when the file is moved between incompatible file systems.
|
||
|
||
\ **Note:** On Linux, only "user" namespace attributes are accessible, namespace prefix should not be included.
|
||
|
||
\ **Note:** On Windows, alternate data streams are used to store extended attributes.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_set_extended_attribute_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **set_extended_attribute_string**\ (\ file\: :ref:`String<class_String>`, attribute_name\: :ref:`String<class_String>`, data\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_FileAccess_method_set_extended_attribute_string>`
|
||
|
||
Writes file extended attribute with name ``attribute_name`` as a UTF-8 encoded string.
|
||
|
||
\ **Note:** This method is implemented on Linux, macOS, and Windows.
|
||
|
||
\ **Note:** Extended attributes support depends on the file system. Attributes will be lost when the file is moved between incompatible file systems.
|
||
|
||
\ **Note:** On Linux, only "user" namespace attributes are accessible, namespace prefix should not be included.
|
||
|
||
\ **Note:** On Windows, alternate data streams are used to store extended attributes.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_set_hidden_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Встановлює файл **прихований** атрибут.
|
||
|
||
\ **Примітка:** Цей метод реалізується на iOS, BSD, macOS та Windows.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_set_read_only_attribute:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Встановіть файл **read only**.
|
||
|
||
\ **Примітка:** Цей метод реалізується на iOS, BSD, macOS та Windows.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_set_unix_permissions:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Встановлює файл УНІКС дозволів.
|
||
|
||
\ **Примітка:** Цей метод реалізується на iOS, Linux/BSD та macOS.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_8:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_8**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_FileAccess_method_store_8>`
|
||
|
||
Зберігає ціле число у файлі як 8 бітів. Це переміщує курсор файлу на 1 байт. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Значення ``value`` має лежати в інтервалі ``[0, 255]``. Будь-яке інше значення призведе до переповнення та перенесення.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції файлу є невизначеним.
|
||
|
||
Щоб зберегти знакове ціле число, використовуйте :ref:`store_64()<class_FileAccess_method_store_64>` або конвертуйте його вручну (див. приклад :ref:`store_16()<class_FileAccess_method_store_16>`).
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_16:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_16**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_FileAccess_method_store_16>`
|
||
|
||
Зберігає ціле число у файлі як 16 бітів. Це просуває курсор файлу на 2 байти. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Значення ``value`` має лежати в інтервалі ``[0, 2^16 - 1]``. Будь-яке інше значення призведе до переповнення та перенесення.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
Щоб зберегти ціле число зі знаком, використовуйте :ref:`store_64()<class_FileAccess_method_store_64>` або збережіть ціле число зі знаком з інтервалу ``[-2^15, 2^15 - 1]`` (тобто зберігаючи один біт для знаку) та обчислюйте його знак вручну під час читання. Наприклад:
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
const MAX_15B = 1 << 15
|
||
const MAX_16B = 1 << 16
|
||
|
||
func unsigned16_to_signed(unsigned):
|
||
return (unsigned + MAX_15B) % MAX_16B - MAX_15B
|
||
|
||
func _ready():
|
||
var f = FileAccess.open("user://file.dat", FileAccess.WRITE_READ)
|
||
f.store_16(-42) # Це завершує цикл і зберігає 65494 (2^16 - 42).
|
||
f.store_16(121) # У межах буде збережено 121.
|
||
f.seek(0) # Повернутися на початок, щоб прочитати збережене значення.
|
||
var read1 = f.get_16() # 65494
|
||
var read2 = f.get_16() # 121
|
||
var converted1 = unsigned16_to_signed(read1) # -42
|
||
var converted2 = unsigned16_to_signed(read2) # 121
|
||
|
||
.. code-tab:: csharp
|
||
|
||
public override void _Ready()
|
||
{
|
||
using var f = FileAccess.Open("user://file.dat", FileAccess.ModeFlags.WriteRead);
|
||
f.Store16(unchecked((ushort)-42)); // Це переноситься та зберігає 65494 (2^16 - 42).
|
||
f.Store16(121); // У межах, буде збережено 121.
|
||
f.Seek(0); // Повернутися на початок, щоб прочитати збережене значення.
|
||
ushort read1 = f.Get16(); // 65494
|
||
ushort read2 = f.Get16(); // 121
|
||
short converted1 = (short)read1; // -42
|
||
short converted2 = (short)read2; // 121
|
||
}
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_32:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_32**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_FileAccess_method_store_32>`
|
||
|
||
Зберігає ціле число у файлі як 32 біти. Це просуває курсор файлу на 4 байти. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Значення ``valve`` має лежати в інтервалі ``[0, 2^32 - 1]``. Будь-яке інше значення призведе до переповнення та переносу.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції файлу є невизначеним.
|
||
|
||
Щоб зберегти знакове ціле число, використовуйте :ref:`store_64()<class_FileAccess_method_store_64>` або конвертуйте його вручну (див. приклад :ref:`store_16()<class_FileAccess_method_store_16>`).
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_64:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_64**\ (\ value\: :ref:`int<class_int>`\ ) :ref:`🔗<class_FileAccess_method_store_64>`
|
||
|
||
Зберігає ціле число у файлі як 64 біти. Це переміщує курсор файлу на 8 байтів. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Значення ``valve`` має лежати в інтервалі ``[-2^63, 2^63 - 1]`` (тобто бути дійсним значенням :ref:`int<class_int>`).
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції файлу є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_buffer:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_FileAccess_method_store_buffer>`
|
||
|
||
Зберігає заданий масив байтів у файлі. Це переміщує курсор файлу на кількість записаних байтів. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції файлу є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_csv_line:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_csv_line**\ (\ values\: :ref:`PackedStringArray<class_PackedStringArray>`, delim\: :ref:`String<class_String>` = ","\ ) :ref:`🔗<class_FileAccess_method_store_csv_line>`
|
||
|
||
Stores 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.
|
||
|
||
Text will be encoded as UTF-8. Returns ``true`` if the operation is successful.
|
||
|
||
\ **Note:** If an error occurs, the resulting value of the file position indicator is indeterminate.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_double:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_double**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_FileAccess_method_store_double>`
|
||
|
||
Зберігає число з плаваючою комою у файлі як 64 біти. Це переміщує курсор файлу на 8 байтів. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_float:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_float**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_FileAccess_method_store_float>`
|
||
|
||
Зберігає число з плаваючою комою у файлі як 32 біти. Це переміщує курсор файлу на 4 байти. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_half:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_half**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_FileAccess_method_store_half>`
|
||
|
||
Зберігає у файлі число з плаваючою комою половинної точності як 16 біт. Це переміщує курсор файлу на 2 байти. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_line:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_line**\ (\ line\: :ref:`String<class_String>`\ ) :ref:`🔗<class_FileAccess_method_store_line>`
|
||
|
||
Зберігає у файлі ``line``, а потім символ нового рядка (``\n``), кодуючи текст як UTF-8. Це переміщує курсор файлу на довжину рядка після символу нового рядка. Кількість записаних байтів залежить від байтів, закодованих UTF-8, що може відрізнятися від :ref:`String.length()<class_String_method_length>`, який підраховує кількість кодових точок UTF-32. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_pascal_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_pascal_string**\ (\ string\: :ref:`String<class_String>`\ ) :ref:`🔗<class_FileAccess_method_store_pascal_string>`
|
||
|
||
Зберігає заданий рядок :ref:`String<class_String>` як рядок у файлі у форматі Pascal (тобто також зберігає довжину рядка). Текст буде закодовано як UTF-8. Це переміщує курсор файлу на кількість записаних байтів залежно від закодованих байтів UTF-8, що може відрізнятися від методу ``String.length``, який підраховує кількість кодових точок UTF-32. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_real:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_real**\ (\ value\: :ref:`float<class_float>`\ ) :ref:`🔗<class_FileAccess_method_store_real>`
|
||
|
||
Зберігає у файлі число з плаваючою комою. Це просуває курсор файлу на 4 або 8 байтів, залежно від точності, що використовується поточною збіркою Godot.
|
||
|
||
Якщо використовується збірка Godot, скомпільована з опцією ``precision=single`` (за замовчуванням), цей метод збереже 32-бітне число з плаваючою комою. В іншому випадку, якщо скомпільовано з опцією ``precision=double``, це збереже 64-бітне число з плаваючою комою. Повертає ``true``, якщо операція виконана успішно.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції у файлі є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_string**\ (\ string\: :ref:`String<class_String>`\ ) :ref:`🔗<class_FileAccess_method_store_string>`
|
||
|
||
Зберігає ``параметр string`` у файлі без символу нового рядка (``\n``), кодуючи текст як UTF-8. Це переміщує курсор файлу на довжину рядка в байтах, закодованих UTF-8, яка може відрізнятися від методу :ref:`String.length()<class_String_method_length>`, який підраховує кількість кодових точок UTF-32. Повертає ``true``, якщо операція успішна.
|
||
|
||
\ **Примітка:** Цей метод призначений для запису текстових файлів. Рядок зберігає як буфер, закодований UTF-8, без довжини рядка або нуля в кінці, що означає, що його не можна легко завантажити назад. Якщо ви хочете зберегти рядок, який можна отримати, у двійковому файлі, розгляньте можливість використання :ref:`store_pascal_string()<class_FileAccess_method_store_pascal_string>`. Для отримання рядків з текстового файлу ви можете використовувати ``get_buffer(length).get_string_from_utf8()`` (якщо ви знаєте довжину) або :ref:`get_as_text()<class_FileAccess_method_get_as_text>`.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції файлу є невизначеним.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_FileAccess_method_store_var:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **store_var**\ (\ value\: :ref:`Variant<class_Variant>`, full_objects\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_FileAccess_method_store_var>`
|
||
|
||
Зберігає будь-яке значення Variant у файлі. Якщо ``full_objects`` має значення ``true``, кодування об'єктів дозволено (і потенційно може містити код). Це переміщує курсор файлу на кількість записаних байтів. Повертає ``true``, якщо операція успішна.
|
||
|
||
Внутрішньо це використовує той самий механізм кодування, що й метод :ref:`@GlobalScope.var_to_bytes()<class_@GlobalScope_method_var_to_bytes>`, як описано в документації :doc:`Binary serialization API <../tutorials/io/binary_serialization_api>`.
|
||
|
||
\ **Примітка:** Не всі властивості включено. Серіалізовано буде лише ті властивості, які налаштовані з встановленим прапорцем :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>`. Ви можете додати новий прапорець використання до властивості, перевизначивши метод :ref:`Object._get_property_list()<class_Object_private_method__get_property_list>` у вашому класі. Ви також можете перевірити, як налаштовано використання властивості, викликавши :ref:`Object._get_property_list()<class_Object_private_method__get_property_list>`. Див. :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>` для можливих прапорців використання.
|
||
|
||
\ **Примітка:** Якщо виникає помилка, результуюче значення індикатора позиції файлу є невизначеним.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (Зазвичай, цей метод перевизначається користувачем, щоб він мав вплив.)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (Цей метод не має побічних ефектів. Не змінює ніяку змінну екземпляра об'єкта.)`
|
||
.. |vararg| replace:: :abbr:`vararg (Цей метод приймає будь-яке число аргументів після описаних тут.)`
|
||
.. |constructor| replace:: :abbr:`constructor (Цей метод використовується для побудови типів.)`
|
||
.. |static| replace:: :abbr:`static (Цей метод не потребує екземпляра для виклику, його можна викликати безпосередньо за допомогою назви класу.)`
|
||
.. |operator| replace:: :abbr:`operator (Цей метод описує дійсний оператор для взаємодії з цим типом як з лівим операндом.)`
|
||
.. |bitfield| replace:: :abbr:`BitField (Це значення є цілим числом, складеним у вигляді бітової маски з наступних прапорів.)`
|
||
.. |void| replace:: :abbr:`void (Значення не повертається.)`
|