Global variables of ballerina.file package
Variable Name | Data Type | Description |
---|---|---|
R | string | The Read access mode |
W | string | The Write access mode |
RW | string | The Read Write access mode |
A | string | The Append access mode |
RA | string | The 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 Name | Data Type | Description |
---|---|---|
source | File | File/Directory that should be copied |
destination | File | Location where the File/Directory should be pasted |
public function <File file> close()
Closes a given file and its stream
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
public function <File file> createNewFile() (boolean, AccessDeniedError, IOError)
Creates a new file given by the path in the File struct
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | Returns true if the new file was successfully created | |
AccessDeniedError | Returns true if the new file was successfully created | |
IOError | Returns true if the new file was successfully created |
public function <File file> delete()
Deletes a file from a given location
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
public function <File file> exists() (boolean)
Checks whether the file exists
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | exists: Returns true if the file exists |
public function <File file> getModifiedTime() (Time, AccessDeniedError, IOError)
Returns the last modified time of the file
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | Returns a Time struct | |
AccessDeniedError | Returns a Time struct | |
IOError | Returns a Time struct |
public function <File file> getName() (string)
Returns the name of the file
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | Returns the file name as a string |
public function <File file> isDirectory() (boolean)
Checks whether the file is a directory
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | isDirectory: 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 Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | Returns 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 Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | Returns true if the user has write access |
public function <File file> list() (File[], AccessDeniedError, IOError)
Lists the files in the specified directory
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
File[] | Returns an array of File structs if successful | |
AccessDeniedError | Returns an array of File structs if successful | |
IOError | Returns 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 Name | Data Type | Description |
---|---|---|
file | File |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | Returns an AccessDeniedError if the user does not have the necessary permissions to modify the directory | |
AccessDeniedError | Returns an AccessDeniedError if the user does not have the necessary permissions to modify the directory | |
IOError | Returns 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 Name | Data Type | Description |
---|---|---|
file | File | The file which needs to be opened |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
accessMode | string | The 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 Name | Data Type | Description |
---|---|---|
file | File | accessMode: Specifies whether the file should be opened for reading or writing (r/w) |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
accessMode | string | Specifies whether the file should be opened for reading or writing (r/w) |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
ByteChannel | ByteChannel 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 Name | Data Type | Description |
---|---|---|
target | File | File/Directory that should be moved |
destination | File | Location where the File/Directory should be moved to |
Structs of ballerina.file package
public struct AccessDeniedError
Fields:
Field Name | Data Type | Description |
---|---|---|
msg | string | |
cause | error | |
stackTrace | StackFrame[] |
public struct File
Fields:
Field Name | Data Type | Description |
---|---|---|
path | string |
public struct FileNotFoundError
Fields:
Field Name | Data Type | Description |
---|---|---|
msg | string | |
cause | error | |
stackTrace | StackFrame[] |
public struct FileNotOpenedError
Fields:
Field Name | Data Type | Description |
---|---|---|
msg | string | |
cause | error | |
stackTrace | StackFrame[] |
public struct IOError
Fields:
Field Name | Data Type | Description |
---|---|---|
msg | string | |
cause | error | |
stackTrace | StackFrame[] |