File | API - NativeScript

Represents a File entity on the file system.

Summary

Constructors

constructor

Properties

extension

Gets the extension of the file.

isLocked

Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.

size

Gets the size in bytes of the file.

Methods

append

append(content: any): Promise<void>

Appends the provided binary content to the file.

appendSync

appendSync(content: any, onError?: (error: any) => any): void

Appends the provided binary content to the file synchronously.

appendText

appendText(content: string, encoding?: string): Promise<any>

Appends the provided string to the file, using the specified encoding (defaults to UTF-8).

appendTextSync

appendTextSync(
  content: string,
  onError?: (error: any) => any,
  encoding?: string
): void

Appends the provided string to the file synchronously, using the specified encoding (defaults to UTF-8).

copy

copy(dest: string): Promise<boolean>

Copies a file to a given path.

copySync

copySync(dest: string, onError?: (error: any) => any): any

Copies a file to a given path.

read

read(): Promise<any>

Reads the binary content of the file asynchronously.

readSync

readSync(onError?: (error: any) => any): any

Reads the binary content of the file synchronously.

readText

readText(encoding?: string): Promise<string>

Reads the content of the file as a string using the specified encoding (defaults to UTF-8).

readTextSync

readTextSync(onError?: (error: any) => any, encoding?: string): string

Reads the content of the file as a string synchronously, using the specified encoding (defaults to UTF-8).

write

write(content: any): Promise<void>

Writes the provided binary content to the file.

writeSync

writeSync(content: any, onError?: (error: any) => any): void

Writes the provided binary content to the file synchronously.

writeText

writeText(content: string, encoding?: string): Promise<any>

Writes the provided string to the file, using the specified encoding (defaults to UTF-8).

writeTextSync

writeTextSync(
  content: string,
  onError?: (error: any) => any,
  encoding?: string
): void

Writes the provided string to the file synchronously, using the specified encoding (defaults to UTF-8).

exists(path: string): boolean

Checks whether a File with the specified path already exists.

fromPath(path: string, copy?: boolean): File

Gets or creates a File entity at the specified path.