Ballerina API Documentation

Global variables of ballerina.file package

Variable NameData TypeDescription
RstringThe Read access mode
WstringThe Write access mode
RWstringThe Read Write access mode
AstringThe Append access mode
RAstringThe Read Append access mode

Functions of ballerina.file package

public function copy(File source, File destination)

Copies a file from a given location to another

Parameters:

Parameter NameData TypeDescription
sourceFileFile/Directory that should be copied
destinationFileDestination directory or path to which the source should be copied

public function <File file> close()

Closes a given file and its stream

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be closed

public function <File file> createNewFile() (boolean, AccessDeniedError, IOError)

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

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be created

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the new file was successfully created
AccessDeniedErrorReturns an AccessDeniedError if the user does not have the necessary permissions to create the file
IOErrorReturns an IOError if the file could not be created due to an I/O error

public function <File file> delete()

Deletes a file from a given location

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be deleted

public function <File file> exists() (boolean)

Checks whether the file exists

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be checked for existence

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the file exists

public function <File file> getModifiedTime() (Time, AccessDeniedError, IOError)

Returns the last modified time of the file

Receiver:

Receiver NameData TypeDescription
fileFileThe file of which the modified time needs to be checked

Return Parameters:

Return VariableData TypeDescription
TimeReturns a Time struct
AccessDeniedErrorReturns an AccessDeniedError if the user does not have the necessary permissions to read the file
IOErrorReturns an IOError if the file could not be read

public function <File file> getName() (string)

Returns the name of the file

Receiver:

Receiver NameData TypeDescription
fileFileThe file of which the name needs to be looked up

Return Parameters:

Return VariableData TypeDescription
stringReturns the file name as a string

public function <File file> isDirectory() (boolean)

Checks whether the file is a directory

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be checked to determine whether it is a directory

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the file is a directory

public function <File file> isReadable() (boolean)

Checks whether the user has read access to the file

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be checked for read permission

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the user has read access

public function <File file> isWritable() (boolean)

Checks whether the user has write access to the file

Receiver:

Receiver NameData TypeDescription
fileFileThe file to be checked for write permission

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the user has write access

public function <File file> list() (File[], AccessDeniedError, IOError)

Lists the files in the specified directory

Receiver:

Receiver NameData TypeDescription
fileFileThe directory whose files list is needed

Return Parameters:

Return VariableData TypeDescription
File[]Returns an array of File structs if successful
AccessDeniedErrorReturns an AccessDeniedError if the user does not have the necessary permissions to read the directory
IOErrorReturns an IOError if the directory could not be opened due to an I/O error

public function <File file> mkdirs() (boolean, AccessDeniedError, IOError)

Creates the directory structure specified by the file struct

Receiver:

Receiver NameData TypeDescription
fileFileThe directory or directory structure to be created

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the directory/directories were successfully created
AccessDeniedErrorReturns an AccessDeniedError if the user does not have the necessary permissions to modify the directory
IOErrorReturns an IOError if the directory could not be created

public function <File file> open(string accessMode)

Retrieves the stream from a local file

Receiver:

Receiver NameData TypeDescription
fileFileThe file which needs to be opened

Parameters:

Parameter NameData TypeDescription
accessModestringThe file access mode used when opening the file

public function <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.

Receiver:

Receiver NameData TypeDescription
fileFileThe file to which a channel needs to be opened

Parameters:

Parameter NameData TypeDescription
accessModestringSpecifies whether the file should be opened for reading or writing (r/w)

Return Parameters:

Return VariableData TypeDescription
ByteChannelByteChannel which will allow to perform I/O operations

public function move(File target, File destination)

Moves a file from a given location to another

Parameters:

Parameter NameData TypeDescription
targetFileFile/Directory that should be moved
destinationFileLocation where the File/Directory should be moved to


Structs of ballerina.file package

public struct AccessDeniedError

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

Fields:

Field Name Data Type Description
msgstringThe error message
causeerrorThe error which caused the access denied error
stackTraceStackFrame[]The stack trace of the error

public struct File

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

Fields:

Field Name Data Type Description
pathstringThe path of the file

public struct FileNotFoundError

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

Fields:

Field Name Data Type Description
msgstringThe error message
causeerrorThe error which caused the file not found error
stackTraceStackFrame[]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.

Fields:

Field Name Data Type Description
msgstringThe error message
causeerrorThe error which caused the file not opened error
stackTraceStackFrame[]The stack trace of the error

public struct IOError

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

Fields:

Field Name Data Type Description
msgstringThe error message
causeerrorThe error which caused the I/O error
stackTraceStackFrame[]The stack trace of the error


Menu

  • Global Variables
    • R
    • W
    • RW
    • A
    • RA
  • Functions
    • copy(File source, File destination)
    • <File> close()
    • <File> createNewFile() (boolean , AccessDeniedError , IOError )
    • <File> delete()
    • <File> exists() (boolean )
    • <File> getModifiedTime() (Time , AccessDeniedError , IOError )
    • <File> getName() (string )
    • <File> isDirectory() (boolean )
    • <File> isReadable() (boolean )
    • <File> isWritable() (boolean )
    • <File> list() (File[] , AccessDeniedError , IOError )
    • <File> mkdirs() (boolean , AccessDeniedError , IOError )
    • <File> open(string accessMode)
    • <File> openChannel(string accessMode) (ByteChannel )
    • move(File target, File destination)
  • Structs
    • AccessDeniedError
    • File
    • FileNotFoundError
    • FileNotOpenedError
    • IOError

Copyright 2017 Ballerina API Documentation