Java Reference
In-Depth Information
Figure 9-1. Relationship between File Connection Optional Package and CLDC
In Figure 9-1, note that the key interface in the API is the FileConnection interface. You
need to use the Connector class from CLDC's Generic Connection Framework (GCF—a primary
networking/communications framework covered in Chapter 10) to obtain an instance of a
FileConnection . Once you have the FileConnection , you can start working with the file system,
perhaps using the IO stream classes of CLDC to read and write data.
Note Incidentally, for some implementations, it may be possible to read from (and even write to) specific
files in an exposed file system without using the File Connection Optional Package. In these cases, you use
InputConnection or OutputConnection from CLDC instead. However, you will not have the ability to
work with directories and discover file names. Using FileConnection gives you full access to all that the
underlying file system has to offer.
Determining If FileConnection API Is Available
It is always a good idea to make sure an optional API is available on a device before attempting
to use it. If you want to confirm that the FileConnection optional API is available on a device,
check for the system property called microedition.io.file.FileConnection.version . All JSR 75
implementations are required to support this property. You can obtain the available version
using this code:
String currentVersion =
System.getProperty("microedition.io.file.FileConnection.version" )
You can also use the returned version to make sure your code is compatible. At this time,
however, only version “1.0” has been defined. Null is returned if the API is not available.
 
Search WWH ::




Custom Search