Java Reference
In-Depth Information
Directory and File Size
Your application may need to determine the available space on a file system associated with a
FileConnection instance. You can call the availableSize() method to find out the available
size in bytes:
public long availableSize()
This returns the total available space in the entire file system. On plug-in memory cards,
this can be up to gigabytes of data. There is another method to find out the size of the storage
area already used up:
public long usedSize()
By adding up the value returned from availableSize() and usedSize() , you can figure out
the total size of the file system.
If you only want to find out the size of the specific file associated with the current
FileConnection instance, use the following method:
public long fileSize()
If the FileConnection instance refers to a directory, you can find out the total size of all the
files in the directory by calling the following method:
public long directorySize()
Creating New Files or Directories
To create a new file, you first have to use Connector.open() with the new file name and
Connector.WRITE mode. A FileConnection will be returned, but the file does not yet exist.
You can confirm its nonexistence by calling
boolean exists() throws SecurityException, IllegalModeException,
ConnectionClosedException
To create the file, you call
public void create() thows IOException
Creating a new directory is similar. Use Connector.open() with the new directory name.
Then call the mkdir() method on the returned FileConnection :
public void mkdir() throws IOException
Note that it is not possible to create a directory using the create() call for a file using a URL
such as “file:///mydir/”. The trailing / will cause the create() call to throw an IOException . Use
only the mkdir() call for directory creation.
Renaming and Deleting Files and Directories
To delete a file or directory, you need to first open it with Connector.WRITE mode enabled, then
call the method:
Search WWH ::




Custom Search