ballerina.file package

public struct AccessDeniedError

Represents an error which occurs when attempting to perform operations on a file without the required privileges.

Field Name Data Type Description Default Value
msg string The error message
cause error The error which caused the access denied error
stackTrace StackFrame[] The stack trace of the error

public struct File

Represents a file in the file system and can perform various file operations on this.

Field Name Data Type Description Default Value
path string The path of the file
  • < File > close ( )

    Closes a given file and its stream

  • < File > createNewFile ( ) ( boolean , AccessDeniedError , IOError )

    Creates a new file given by the path in the File struct

    Return Variable Data Type Description
    boolean
    AccessDeniedError
    IOError
  • < File > delete ( )

    Deletes a file from a given location

  • < File > exists ( ) ( boolean )

    Checks whether the file exists

    Return Variable Data Type Description
    boolean
  • < File > getModifiedTime ( ) ( Time , AccessDeniedError , IOError )

    Returns the last modified time of the file

    Return Variable Data Type Description
    Time
    AccessDeniedError
    IOError
  • < File > getName ( ) ( string )

    Returns the name of the file

    Return Variable Data Type Description
    string
  • < File > isDirectory ( ) ( boolean )

    Checks whether the file is a directory

    Return Variable Data Type Description
    boolean
  • < File > isReadable ( ) ( boolean )

    Checks whether the user has read access to the file

    Return Variable Data Type Description
    boolean
  • < File > isWritable ( ) ( boolean )

    Checks whether the user has write access to the file

    Return Variable Data Type Description
    boolean
  • < File > list ( ) ( File[] , AccessDeniedError , IOError )

    Lists the files in the specified directory

    Return Variable Data Type Description
    File[]
    AccessDeniedError
    IOError
  • < File > mkdirs ( ) ( boolean , AccessDeniedError , IOError )

    Creates the directory structure specified by the file struct

    Return Variable Data Type Description
    boolean
    AccessDeniedError
    IOError
  • < File > open ( string accessMode )

    Retrieves the stream from a local file

    Parameter Name Data Type Description
    accessMode string The file access mode used when opening the file
  • < File > openChannel ( string accessMode ) ( ByteChannel )

    Function to return a ByteChannel related to the file. This ByteChannel can then be used to read/write from/to the file.

    Parameter Name Data Type Description
    accessMode string Specifies whether the file should be opened for reading or writing (r/w)

    Return Variable Data Type Description
    ByteChannel

public struct FileNotFoundError

Represents an error which occurs when attempting to perform operations on a non-existent file.

Field Name Data Type Description Default Value
msg string The error message
cause error The error which caused the file not found error
stackTrace StackFrame[] The stack trace of the error

public struct FileNotOpenedError

Represents an error which occurs when attempting to perform operations on a file without opening it.

Field Name Data Type Description Default Value
msg string The error message
cause error The error which caused the file not opened error
stackTrace StackFrame[] The stack trace of the error

public struct IOError

Represents an I/O error which could occur when processing a file.

Field Name Data Type Description Default Value
msg string The error message
cause error The error which caused the I/O error
stackTrace StackFrame[] The stack trace of the error

public function copy ( File source , File destination )

Copies a file from a given location to another

Parameter Name Data Type Description
source File File/Directory that should be copied
destination File Destination directory or path to which the source should be copied

public function move ( File target , File destination )

Moves a file from a given location to another

Parameter Name Data Type Description
target File File/Directory that should be moved
destination File Location where the File/Directory should be moved to

R

Attribute Name Data Type Description
R string The Read access mode

W

Attribute Name Data Type Description
W string The Write access mode

RW

Attribute Name Data Type Description
RW string The Read Write access mode

A

Attribute Name Data Type Description
A string The Append access mode

RA

Attribute Name Data Type Description
RA string The Read Append access mode