Java Reference
In-Depth Information
5. Perform your input and output using the stream you got from step 4.
6. Close the stream.
7. Close the FileConnection .
Of course, you can do several other things, too. You can remove a file or directory,
change its access settings, and enumerate the contents of a directory. Finally, you can lis-
ten for changes on the file system, which alert you of status changes such as the insertion
of a removable storage card like a SanDisk microSD card.
The file system on a device is typically organized as a tree, just as on a FAT32 file sys-
tem (although the actual nature of the file system might be something totally different).
A key difference, however, is that the file system can have multiple roots, one for each
kind of removable or permanent file system. Thus, SD1/ might refer to the contents of the
first SD card, while internal would refer to the internal store. Unfortunately, there's no
standard for determining these names; the only way to find out what they mean is to
query the system using the change-notification interface provided. (I show you how to
do that later, in the section titled “Listening for File System Changes.”)
Determining If the FCOP Is Present
Before you begin using the FCOP, you should check to see if it's present. You can do this
by interrogating the system for the version of the FileConnection interface, as shown in
Listing 7-1.
Listing 7-1. Interrogating the System for the FileConnection Version
String cv = System.getProperty(
"microedition.io.file.FileConnection.version");
if (cv != null) {
// Mark that you have the interface available, or just
// do your file I/O here.
}
This check returns a version string such as "1.0" , but if it returns anything non- null ,
you know the FCOP is present on the target running your application.
Obtaining a FileConnection Instance
As I indicated previously, you use the Connection class to obtain an instance of
FileConnection , with which you actually perform your file operations. You do this
using its open method, like this:
 
Search WWH ::




Custom Search