Version: Unity 6 (6000.0)
LanguageEnglish
  • C#

FileHandle

struct in Unity.IO.LowLevel.Unsafe

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A handle to an asynchronously opened file.

Opening a file with AsyncReadManager.OpenFileAsync returns a FileHandle instance. You can use this handle to check the status of the asynchronous open operation.

Use AsyncReadManager.Read to read the data in the file after the open operation is complete. This will automatically wait for the open operation to complete, and give the ReadHandle a WaitingOnJob ReadStatus while it does so. If using AsyncReadManager.ReadDeferred instead, you should make sure that the passed in JobHandle waits on this JobHandle to schedule the read job after the open operation finishes.

Always call Close on the FileHandle when finished to avoid memory leaks and holding a file open. You must call close even if the open operation failed, to dispose of the FileHandle.

To write to a file, use the standard .NET File APIs, such as System.IO.StreamWriter. You must close this FileHandle before you can read or write to the file with other APIs. (If a file is held open by the AsyncReadManager's file cache, you can use AsyncReadManager.CloseCachedFileAsync to close it, but do not use that API to close files for which you have a FileHandle as these are not in the cache.)

Properties

JobHandleThe JobHandle of the asynchronous file open operation begun by the call to AsyncReadManager.OpenFileAsync that returned this FileHandle instance.
StatusThe current status of this FileHandle.

Public Methods

CloseAsynchronously closes the file referenced by this FileHandle and disposes the FileHandle instance.
IsValidReports whether this FileHandle instance is valid.