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 Apend 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
destinationFileLocation where the File/Directory should be pasted

public function <File file> close()

Closes a given file and its stream

Receiver:

Receiver NameData TypeDescription
fileFile

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

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

Receiver:

Receiver NameData TypeDescription
fileFile

Return Parameters:

Return VariableData TypeDescription
booleanReturns true if the new file was successfully created
AccessDeniedErrorReturns true if the new file was successfully created
IOErrorReturns true if the new file was successfully created

public function <File file> delete()

Deletes a file from a given location

Receiver:

Receiver NameData TypeDescription
fileFile

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

Checks whether the file exists

Receiver:

Receiver NameData TypeDescription
fileFile

Return Parameters:

Return VariableData TypeDescription
booleanexists: Returns 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
fileFile

Return Parameters:

Return VariableData TypeDescription
TimeReturns a Time struct
AccessDeniedErrorReturns a Time struct
IOErrorReturns a Time struct

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

Returns the name of the file

Receiver:

Receiver NameData TypeDescription
fileFile

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
fileFile

Return Parameters:

Return VariableData TypeDescription
booleanisDirectory: Returns 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
fileFile

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
fileFile

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
fileFile

Return Parameters:

Return VariableData TypeDescription
File[]Returns an array of File structs if successful
AccessDeniedErrorReturns an array of File structs if successful
IOErrorReturns an array of File structs if successful

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

Creates the directory structure specified by the file struct

Receiver:

Receiver NameData TypeDescription
fileFile

Return Parameters:

Return VariableData TypeDescription
booleanReturns an AccessDeniedError if the user does not have the necessary permissions to modify the directory
AccessDeniedErrorReturns an AccessDeniedError if the user does not have the necessary permissions to modify the directory
IOErrorReturns an AccessDeniedError if the user does not have the necessary permissions to modify the directory

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 return the ByteChannel related to the file

Receiver:

Receiver NameData TypeDescription
fileFileaccessMode: Specifies whether the file should be opened for reading or writing (r/w)

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

Fields:

Field NameData TypeDescription
msgstring
causeerror
stackTraceStackFrame[]

public struct File

Fields:

Field NameData TypeDescription
pathstring

public struct FileNotFoundError

Fields:

Field NameData TypeDescription
msgstring
causeerror
stackTraceStackFrame[]

public struct FileNotOpenedError

Fields:

Field NameData TypeDescription
msgstring
causeerror
stackTraceStackFrame[]

public struct IOError

Fields:

Field NameData TypeDescription
msgstring
causeerror
stackTraceStackFrame[]


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