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 |
---|---|---|---|
message | string | The error message | |
cause | error | The error which caused the access denied 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 Returns true if the new file was successfully created AccessDeniedError Returns an AccessDeniedError if the user does not have the necessary permissions to create the file IOError Returns an IOError if the file could not be created due to an I/O error -
< File > delete ( )
Deletes a file from a given location
-
< File > exists ( ) ( boolean )
Checks whether the file exists
Return Variable Data Type Description boolean Returns true if the file exists -
< File > getModifiedTime ( ) ( Time , AccessDeniedError , IOError )
Returns the last modified time of the file
Return Variable Data Type Description Time Returns a Time struct AccessDeniedError Returns an AccessDeniedError if the user does not have the necessary permissions to read the file IOError Returns an IOError if the file could not be read -
< File > getName ( ) ( string )
Returns the name of the file
Return Variable Data Type Description string Returns the file name as a string -
< File > isDirectory ( ) ( boolean )
Checks whether the file is a directory
Return Variable Data Type Description boolean Returns true if the file is a directory -
< File > isReadable ( ) ( boolean )
Checks whether the user has read access to the file
Return Variable Data Type Description boolean Returns true if the user has read access -
< File > isWritable ( ) ( boolean )
Checks whether the user has write access to the file
Return Variable Data Type Description boolean Returns true if the user has write access -
< File > list ( ) ( File[] , AccessDeniedError , IOError )
Lists the files in the specified directory
Return Variable Data Type Description File[] Returns an array of File structs if successful AccessDeniedError Returns an AccessDeniedError if the user does not have the necessary permissions to read the directory IOError Returns an IOError if the directory could not be opened due to an I/O error -
< File > mkdirs ( ) ( boolean , AccessDeniedError , IOError )
Creates the directory structure specified by the file struct
Return Variable Data Type Description boolean Returns true if the directory/directories were successfully created AccessDeniedError Returns an AccessDeniedError if the user does not have the necessary permissions to modify the directory IOError Returns an IOError if the directory could not be created -
< 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 ByteChannel which will allow to perform I/O operations
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 |
---|---|---|---|
message | string | The error message | |
cause | error | The error which caused the file not found 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 |
---|---|---|---|
message | string | The error message | |
cause | error | The error which caused the file not opened error |
public struct IOError
Represents an I/O error which could occur when processing a file.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
message | string | The error message | |
cause | error | The error which caused the I/O 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 |