FileOpen

Opens a file for reading or writing and returns a file object for future operations

Method Signature

FileOpen(file=[string], mode=[string], charset=[string], seekable=[boolean])

Arguments

Argument
Type
Required
Description
Default

file

string

true

The file to open.

mode

string

false

The mode to open the file in. Defaults to "read".

read

charset

string

false

The character set to use when reading or writing the file. Defaults to "utf-8".

utf-8

seekable

boolean

false

Whether the file should be opened as seekable. Defaults to false.

Examples

Opens a file, reads a line then closes it.

// Open File
var fileObject = fileOpen( "/path/to/file.txt" );
// Perform Actions
try {
	// Read Line
	writeOutput( fileReadLine( fileObject ) );
}
// Error Handling
 catch (any ex) {
	// Report Exception
	writeDump( ex );
}finally {
	// Always Close
	// Close File
	fileClose( fileObject );
}

Additional Examples

myFile = fileOpen( "filepath/filename.ext" );
writeDump( myfile );
// how to access the underlying resource provider info
f = "ram://demo.txt";
fileWrite( f, "demo" );
dump( f.getResource().getResourceProvider().getScheme() );
 // ram ( i.e. the resource provider type)

Last updated

Was this helpful?