File Javascript library

The File class provides means to read data from the file system and from an HTTP connection.


int list (String path):
Returns the number of files residing in the phone local file system and located at path, considered as a directory. Path must start with "file://".
The file system often define root partitions to differentiate the phone memory from an extension card.
These roots are automatically managed by this function and are treated as sub directories of "file://".

String getName (int n):
Returns the name of the file at position n inside path (list() must have been called before).

bool isDir (int n):
Returns true if the entry at position n in the directory referenced by the last list command is also a directory (so list() must have been obviously called before).

String getFullPath (int n):
Returns the full path of the entry n.

int open (String path, bool async):
Open the file referenced by the path parameter for reading and return an identifier for future reference (close, getLine, oef, getStatus, ...).
If path starts with "http://" an HTTP connection is opened.
If path starts with "file:///" a file connection with the file system is created.
Otherwise, the content is read from the midlet resource.
If async is true the function returns immediately and the script must call getStatus periodically to check whether getLine or getData can be called.

void close (int i):
Close the stream associated with identifier i.

String getLine (int i):
Returns the next line (chars up to "\n") in stream associated with identifier i.

bool eof (int i):
Returns whether the stream associated with i reached end of file.

int getData (int i, bool async, String encoding):
Starts reading data. If async is true returns immediately "", otherwise returns all available data. encoding is optional (Default: UTF-8).

int getStatus (int i):
Returns the current status, see Constants below.

bool isAvailable ():
Returns true (1) if the device supports file system methods (list, getName, isDir, getFullPath).

void clean ():
Close all opened at once files.


ERROR:
An error occurred (e.g. file does not exists).

READY:
File is open and ready for starting data transfer.

OPENING:
File is being open (i.e. communication in progress) .

LOADING:
Data is loading (transferring).

LOADED:
Data is fully loaded but not read yet.

CLOSED:
Data has been read.


In a widget context, the access to files on the file system is not available and the following methods will not work : list, getName, isDir, getFullPath.
The 'file://' scheme is not supported in the open() method.


Find the entire source code into the DataLoader prototype.