File System
TT.GetFileSystemManager() returns a TTFileSystemManager. User data must be written under TTFileSystemManager.USER_DATA_PATH. Do not treat local file behavior in Unity Editor as the result on a real device in the TikTok App.
Field names in asynchronous parameter objects are case-sensitive. For example, WriteFileStringParam.filePath starts with a lowercase letter, while AppendFileStringParam.FilePath starts with an uppercase letter. Use the field names defined by the current C# types.
Callbacks
Field | Type | Description |
|
| Called when the API succeeds. T is the result type of the current API. |
|
| Called when the API fails. Use |
TT.GetFileSystemManager()
Gets the file-system manager. Use this object for subsequent file and directory operations.
Signature
public static TTFileSystemManager GetFileSystemManager()Return value
A TTFileSystemManager file-system manager.
Example
TTFileSystemManager fs = TT.GetFileSystemManager();
string userRoot = TTFileSystemManager.USER_DATA_PATH;TTFileSystemManager.WriteFile(param)
Writes a string or binary file asynchronously.
Signature
public abstract void WriteFile(WriteFileStringParam param)
public abstract void WriteFile(WriteFileParam param)Parameters
Parameter object | Field | Type | Description |
|
|
| Destination file path. |
|
|
| String to write. |
|
|
| Character encoding. The default is |
|
|
| Destination file path. |
|
|
| Binary data to write. |
Callbacks
Both success and fail return TTBaseResponse, which contains errCode and errMsg.
Example
fs.WriteFile(new WriteFileStringParam
{
filePath = TTFileSystemManager.USER_DATA_PATH + "/player.json",
data = json,
encoding = "utf8",
success = _ => Debug.Log("File saved."),
fail = error => Debug.LogError($"{error.errCode}: {error.errMsg}")
});TTFileSystemManager.WriteFileSync(filePath, data, encoding)
Writes a string or binary file synchronously.
Signature
public abstract string WriteFileSync(string filePath, string data, string encoding = "utf8")
public abstract string WriteFileSync(string filePath, byte[] data)Parameters
Parameter | Type | Required | Description |
|
| Yes | Destination file path. |
|
| Yes | String or binary data to write. |
|
| No | Character encoding for string data. The default is |
Return value
Returns an empty string on success, or an error message on failure.
Example
string error = fs.WriteFileSync(saveFile, json, "utf8");
if (!string.IsNullOrEmpty(error))
{
Debug.LogError(error);
}TTFileSystemManager.ReadFile(param)
Reads a string or binary file asynchronously. When encoding is set, read the string from stringData. When it is not set, read the binary data from binData.
Signature
public abstract void ReadFile(ReadFileParam param)Parameters
Field | Type | Required | Description |
|
| Yes | Path of the file to read. |
|
| No | Character encoding. If omitted, the file is read as binary data. |
Return value
Field | Type | Description |
|
| String decoded with the specified character encoding. |
|
| Binary data returned when no character encoding is specified. |
|
| Result status and error message. |
Example
fs.ReadFile(new ReadFileParam
{
filePath = saveFile,
encoding = "utf8",
success = result => Debug.Log(result.stringData),
fail = error => Debug.LogError($"{error.errCode}: {error.errMsg}")
});TTFileSystemManager.ReadFileSync(filePath, encoding)
Reads a string or binary file synchronously.
Signature
public abstract byte[] ReadFileSync(string filePath)
public abstract string ReadFileSync(string filePath, string encoding)Parameters
Parameter | Type | Required | Description |
|
| Yes | Path of the file to read. |
|
| Yes for string reads | Character encoding. It cannot be empty. |
Return value
Returns byte[] or string. Returns null if the read fails.
Example
string savedJson = fs.ReadFileSync(saveFile, "utf8");
if (savedJson != null)
{
Debug.Log(savedJson);
}TTFileSystemManager.Access(param)
Checks asynchronously whether a file or directory exists.
Signature
public abstract void Access(AccessParam param)Parameters
AccessParam.path is the path of the file or directory to check. success is called if it exists. fail is called if it does not exist or the check fails.
Example
fs.Access(new AccessParam
{
path = saveFile,
success = _ => Debug.Log("File exists."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.AccessSync(path)
Checks synchronously whether a file or directory exists.
Signature
public abstract bool AccessSync(string path)Return value
Returns true if the path exists. Returns false if it does not exist or the check fails.
Example
bool exists = fs.AccessSync(saveFile);TTFileSystemManager.CopyFile(param)
Copies a file asynchronously.
Signature
public abstract void CopyFile(CopyFileParam param)Parameters
Field | Type | Description |
|
| Source file path. |
|
| Destination file path. |
Example
fs.CopyFile(new CopyFileParam
{
srcPath = saveFile,
destPath = backupFile,
success = _ => Debug.Log("File copied."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.CopyFileSync(srcPath, destPath)
Copies a file synchronously.
Signature
public abstract string CopyFileSync(string srcPath, string destPath)Return value
Returns an empty string on success, or an error message on failure.
Example
string error = fs.CopyFileSync(saveFile, backupFile);TTFileSystemManager.RenameFile(param)
Moves or renames a file asynchronously.
Signature
public abstract void RenameFile(RenameFileParam param)Parameters
Field | Type | Description |
|
| Source file path. |
|
| Destination file path. |
Example
fs.RenameFile(new RenameFileParam
{
srcPath = temporaryFile,
destPath = saveFile,
success = _ => Debug.Log("File renamed."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.RenameFileSync(srcPath, destPath)
Moves or renames a file synchronously.
Signature
public abstract string RenameFileSync(string srcPath, string destPath)Return value
Returns an empty string on success, or an error message on failure.
Example
string error = fs.RenameFileSync(temporaryFile, saveFile);TTFileSystemManager.Unlink(param)
Deletes a file asynchronously.
Signature
public abstract void Unlink(UnlinkParam param)Parameters
UnlinkParam.filePath is the path of the file to delete.
Example
fs.Unlink(new UnlinkParam
{
filePath = obsoleteFile,
success = _ => Debug.Log("File removed."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.UnlinkSync(filePath)
Deletes a file synchronously.
Signature
public abstract string UnlinkSync(string filePath)Return value
Returns an empty string on success, or an error message on failure.
Example
string error = fs.UnlinkSync(obsoleteFile);TTFileSystemManager.Mkdir(param)
Creates a directory asynchronously.
Signature
public abstract void Mkdir(MkdirParam param)Parameters
Field | Type | Default | Description |
|
| - | Directory path to create. |
|
|
| Whether to create missing parent directories first. |
Example
fs.Mkdir(new MkdirParam
{
dirPath = saveDir,
recursive = true,
success = _ => Debug.Log("Directory created."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.MkdirSync(dirPath, recursive)
Creates a directory synchronously.
Signature
public abstract string MkdirSync(string dirPath, bool recursive = false)Return value
Returns an empty string on success, or an error message on failure.
Example
string error = fs.MkdirSync(saveDir, recursive: true);TTFileSystemManager.Rmdir(param)
Deletes a directory asynchronously. Recursive deletion also removes its subdirectories and files.
Signature
public abstract void Rmdir(RmdirParam param)Parameters
Field | Type | Default | Description |
|
| - | Directory path to delete. |
|
|
| Whether to delete the directory contents recursively. |
Example
fs.Rmdir(new RmdirParam
{
dirPath = obsoleteDirectory,
recursive = true,
success = _ => Debug.Log("Directory removed."),
fail = error => Debug.LogError(error.errMsg)
});Recursive deletion cannot be undone. Before calling this API, make sure the directory does not contain saves or caches that must be retained.
TTFileSystemManager.RmdirSync(dirPath, recursive)
Deletes a directory synchronously.
Signature
public abstract string RmdirSync(string dirPath, bool recursive = false)Return value
Returns an empty string on success, or an error message on failure.
Example
string error = fs.RmdirSync(obsoleteDirectory, recursive: true);TTFileSystemManager.ReadDir(param)
Reads the names of files and subdirectories in a directory asynchronously.
Signature
public abstract void ReadDir(ReadDirParam param)Parameters
Object | Field | Type | Description |
|
|
| Directory path to read. |
|
|
| Names of files and subdirectories in the directory. |
Example
fs.ReadDir(new ReadDirParam
{
DirPath = saveDir,
success = result => Debug.Log(string.Join(", ", result.files)),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.ReadDirSync(dirPath)
Reads the names of files and subdirectories in a directory synchronously.
Signature
public abstract string[] ReadDirSync(string dirPath)Return value
Returns an array containing the directory entry names.
Example
string[] entries = fs.ReadDirSync(saveDir);
foreach (string entry in entries)
{
Debug.Log(entry);
}TTFileSystemManager.Stat(param)
Reads status information for a file or directory asynchronously.
Signature
public abstract void Stat(StatParam param)Parameters
Object | Field | Type | Description |
|
|
| File or directory path. |
|
|
| File or directory status. |
Return value
TTStatInfo contains size, mode, lastAccessedTime, and lastModifiedTime. Use IsFile() and IsDirectory() to determine the entry type.
Example
fs.Stat(new StatParam
{
path = saveFile,
success = result => Debug.Log($"Size: {result.stat.size}"),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.StatSync(path, throwException)
Reads status information for a file or directory synchronously.
Signature
public abstract TTStatInfo StatSync(string path, bool throwException = false)Parameters
Parameter | Type | Default | Description |
|
| - | File or directory path. |
|
|
| Whether to throw an exception when access fails. |
Return value
Returns TTStatInfo on success. Returns null when access fails and no exception is thrown.
Example
TTStatInfo info = fs.StatSync(saveFile);
if (info != null && info.IsFile())
{
Debug.Log($"File size: {info.size} bytes");
}TTFileSystemManager.GetSavedFileList(param)
Gets the saved-file list from the user directory asynchronously. The current source marks this API as available on WebGL.
Signature
public abstract void GetSavedFileList(GetSavedFileListParam param)Success result
TTGetSavedFileListResponse.fileList is a TTFileInfo[]. Each entry contains filePath, size, createTime, and mode.
Example
fs.GetSavedFileList(new GetSavedFileListParam
{
success = result =>
{
foreach (TTFileInfo file in result.fileList)
{
Debug.Log($"{file.filePath}: {file.size} bytes");
}
},
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.AppendFile(param)
Appends string or binary data to the end of a file asynchronously. Creates the file when it does not exist.
Signature
public abstract void AppendFile(AppendFileStringParam param)
public abstract void AppendFile(AppendFileParam param)Parameters
Parameter object | Field | Type | Description |
|
|
| Target file path. |
|
|
| String to append. |
|
|
| Character encoding. The default is |
|
|
| Target file path. |
|
|
| Binary data to append. |
Example
fs.AppendFile(new AppendFileStringParam
{
FilePath = logFile,
Data = "level_complete\n",
Encoding = "utf8",
success = _ => Debug.Log("Log appended."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.AppendFileSync(filePath, data, encoding)
Appends string or binary data to the end of a file synchronously.
Signature
public abstract string AppendFileSync(string filePath, string data, string encoding = "utf8")
public abstract string AppendFileSync(string filePath, byte[] data)Return value
Returns an empty string on success or an error message on failure.
Example
string error = fs.AppendFileSync(logFile, "level_complete\n", "utf8");TTFileSystemManager.Truncate(param)
Truncates a file to the specified byte length asynchronously.
Signature
public abstract void Truncate(TruncateParam param)Parameters
Field | Type | Description |
|
| File path to truncate. |
|
| File length in bytes after truncation. |
Example
fs.Truncate(new TruncateParam
{
FilePath = logFile,
Length = 1024,
success = _ => Debug.Log("File truncated."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.TruncateSync(filePath, length)
Truncates a file to the specified byte length synchronously.
Signature
public abstract string TruncateSync(string filePath, int length)Return value
Returns an empty string on success or an error message on failure.
Example
string error = fs.TruncateSync(logFile, 1024);TTFileSystemManager.Open(param)
Opens a file asynchronously and returns a file descriptor.
Signature
public abstract void Open(OpenParam param)Parameters and result
Object | Field | Type | Description |
|
|
| File path. |
|
|
| File open mode. |
|
|
| File descriptor used by subsequent streaming APIs. |
Example
fs.Open(new OpenParam
{
filePath = saveFile,
flag = "r",
success = result => Debug.Log($"fd: {result.fd}"),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.OpenSync(param)
Opens a file synchronously and returns a file descriptor.
Signature
public abstract string OpenSync(OpenSyncParam param)Parameters
OpenSyncParam contains filePath and flag.
Return value
Returns the file descriptor used by subsequent streaming APIs.
Example
string fd = fs.OpenSync(new OpenSyncParam
{
filePath = saveFile,
flag = "r"
});TTFileSystemManager.Read(param)
Reads a specified number of bytes from an open file descriptor asynchronously.
Signature
public abstract void Read(ReadParam param)Parameters
Field | Type | Description |
|
| File descriptor returned by |
|
| Buffer that receives the data. |
|
| Write offset in the buffer. |
|
| Number of bytes to read. |
|
| Read position in the file. |
Success result
TTReadResponse contains arrayBuffer and bytesRead.
Example
fs.Read(new ReadParam
{
fd = fd,
arrayBuffer = new byte[1024],
offset = 0,
length = 1024,
position = 0,
success = result => Debug.Log($"Read {result.bytesRead} bytes."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.ReadSync(param)
Reads a specified number of bytes from an open file descriptor synchronously.
Signature
public abstract ReadResult ReadSync(ReadSyncParam param)Parameters
ReadSyncParam contains fd, arrayBuffer, offset, length, and position.
Return value
ReadResult contains arrayBuffer and bytesRead.
Example
ReadResult result = fs.ReadSync(new ReadSyncParam
{
fd = fd,
arrayBuffer = new byte[1024],
offset = 0,
length = 1024,
position = 0
});TTFileSystemManager.Write(param)
Writes string or binary data to an open file descriptor asynchronously.
Signature
public abstract void Write(WriteStringParam param)
public abstract void Write(WriteBinParam param)Parameters
Field | Type | Description |
|
| File descriptor. |
|
| Data to write. |
|
| Start offset in binary data. |
|
| Number of binary bytes to write. |
|
| String encoding. |
|
| Write position in the file. |
Success result
TTWriteResponse.bytesWritten is the actual number of bytes written.
Example
fs.Write(new WriteStringParam
{
fd = fd,
data = "checkpoint",
encoding = "utf8",
position = 0,
success = result => Debug.Log($"Wrote {result.bytesWritten} bytes."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.WriteSync(param)
Writes string or binary data to an open file descriptor synchronously.
Signature
public abstract WriteResult WriteSync(WriteStringSyncParam param)
public abstract WriteResult WriteSync(WriteBinSyncParam param)Parameters
The parameter object contains fd, data, offset, length, encoding, and optional position. Use the matching parameter type for the string or binary overload.
Return value
WriteResult.bytesWritten is the actual number of bytes written.
Example
WriteResult result = fs.WriteSync(new WriteStringSyncParam
{
fd = fd,
data = "checkpoint",
encoding = "utf8"
});TTFileSystemManager.Close(param)
Closes a file descriptor asynchronously. Close it after streaming reads or writes are complete.
Signature
public abstract void Close(CloseParam param)Parameters
CloseParam.fd is the file descriptor to close.
Example
fs.Close(new CloseParam
{
fd = fd,
success = _ => Debug.Log("File closed."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.CloseSync(param)
Closes a file descriptor synchronously.
Signature
public abstract void CloseSync(CloseSyncParam param)Parameters
CloseSyncParam.fd is the file descriptor to close.
Example
fs.CloseSync(new CloseSyncParam { fd = fd });TTFileSystemManager.ReadCompressedFile(param)
Reads and decompresses a file asynchronously.
Signature
public abstract void ReadCompressedFile(ReadCompressedFileParam param)Parameters and result
Object | Field | Type | Description |
|
|
| Compressed-file path. |
|
|
| Compression algorithm used by the file. |
|
|
| Decompressed file content. |
Example
fs.ReadCompressedFile(new ReadCompressedFileParam
{
filePath = compressedFile,
compressionAlgorithm = "gzip",
success = result => Debug.Log($"Read {result.arrayBuffer.Length} bytes."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.ReadCompressedFileSync(param)
Reads and decompresses a file synchronously.
Signature
public abstract byte[] ReadCompressedFileSync(ReadCompressedFileSyncParam param)Parameters
ReadCompressedFileSyncParam contains filePath and compressionAlgorithm.
Return value
Returns the decompressed binary data.
Example
byte[] bytes = fs.ReadCompressedFileSync(new ReadCompressedFileSyncParam
{
filePath = compressedFile,
compressionAlgorithm = "gzip"
});TTFileSystemManager.Fstat(param)
Gets file status from a file descriptor asynchronously.
Signature
public abstract void Fstat(FstatParam param)Parameters and result
FstatParam.fd is the file descriptor. FstatResponse.stats in the success result is a TTStatInfo.
Example
fs.Fstat(new FstatParam
{
fd = fd,
success = result => Debug.Log($"Size: {result.stats.size}"),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.FstatSync(param)
Gets file status from a file descriptor synchronously.
Signature
public abstract TTStatInfo FstatSync(FstatSyncParam param)Parameters
FstatSyncParam.fd is the file descriptor.
Return value
Returns TTStatInfo.
Example
TTStatInfo info = fs.FstatSync(new FstatSyncParam { fd = fd });TTFileSystemManager.Ftruncate(param)
Truncates a file through its file descriptor asynchronously.
Signature
public abstract void Ftruncate(FtruncateParam param)Parameters
Field | Type | Description |
|
| File descriptor. |
|
| File length in bytes after truncation. |
Example
fs.Ftruncate(new FtruncateParam
{
fd = fd,
length = 1024,
success = _ => Debug.Log("File truncated."),
fail = error => Debug.LogError(error.errMsg)
});TTFileSystemManager.FtruncateSync(param)
Truncates a file through its file descriptor synchronously.
Signature
public abstract void FtruncateSync(FtruncateSyncParam param)Parameters
FtruncateSyncParam contains fd and length.
Example
fs.FtruncateSync(new FtruncateSyncParam
{
fd = fd,
length = 1024
});TTFileSystemManager.GetLocalCachedPathForUrl(url)
Gets the local cached-file path for a URL. The current source marks this API as available on WebGL.
Signature
public abstract string GetLocalCachedPathForUrl(string url)Return value
Returns a local cache path that starts with scfile://user.
Example
string cachedPath = fs.GetLocalCachedPathForUrl(resourceUrl);TTFileSystemManager.IsUrlCached(url)
Checks whether a URL already has a local cached file. The current source marks this API as available on WebGL.
Signature
public abstract bool IsUrlCached(string url)Return value
Returns true when the URL is cached; otherwise, returns false.
Example
bool cached = fs.IsUrlCached(resourceUrl);TTFileSystemManager.CleanAllFileCache(callback)
Clears files managed by the SDK cache.
Signature
public static void CleanAllFileCache(Action<bool> callback)Callback parameter
Returns whether the cache cleanup succeeded.
Example
TT.CleanAllFileCache(success =>
Debug.Log($"File cache cleared: {success}"));Do not use CleanAllFileCache as a replacement for game-save management. Your game must still version, migrate, overwrite, and delete data created through storage and file APIs.