| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface FileConnection
This interface is intended to access files or directories that are located on removeable media and/or file systems on a device.
 The internal file systems that are in memory on a device can also be accessed through
 this class, provided there is underlying hardware and operating system support.
 If file connections are not supported for a particular media or file system,
 attempts to open a file connection to the media or file system through
 Connector.open() results in the
 javax.microedition.io.IOException being thrown.
 
The format of the input string used to access a FileConnection through 
 Connector.open() must follow the format of a fully-qualified,
 absolute path file name as described by the file 
 URL format in IETF RFCs 1738 and 2396.  Further detail for the File 
 URL format can be found in the javax.microedition.io.file package description. 
 
A single connection object only references one file or
 directory at a time. In some cases a connection object can be reused to
 refer to a different file or directory from the one it was originally associated with
 (see FileConnection.setFileConnection(java.lang.String)).  In general, the best approach to reference
 a different file or directory is by establishing a completely separate
 connection through the Connector.open() method.
FileConnection is different from other Generic Connection Framework 
 connections in that a connection object can be successfully returned from
 the Connector.open() method without actually referencing an
 existing entity (in this case, a file or directory). This behavior
 allows the creation of new files and directories on a file system.
 For example, the following code can be used to create
 a new file on a file system, where CFCard is a valid existing file
 system root name for a given implementation:
 
 try {
     FileConnection fconn = (FileConnection)Connector.open("file:///CFCard/newfile.txt");
     // If no exception is thrown, then the URI is valid, but the file may or may not exist.
     if (!fconn.exists())
         fconn.create();  // create the file if it doesn't exist
     fconn.close();
 }
 catch (IOException ioe) {
 }
 
 
 You should always check for the existence of a file or directory
 after a connection is established to determine if the file or directory
 actually exists. Similarly, files or directories can be deleted using the
 FileConnection.delete() method, and you should close the connection
 immediately after deletion to prevent a connection from trying to access
 a nonexistent file or directory.
 
 A file connection's open status is unaffected by the opening and closing of
 input and output streams from the file connection; the file connection stays
 open until close() is invoked on the FileConnection instance.
 Input and output streams can be opened and closed multiple times on a
 FileConnection instance.
 
 All FileConnection instances have one underlying 
 InputStream and one OutputStream. Opening a 
 DataInputStream counts as opening an InputStream,
 and opening a DataOutputStream counts as opening an 
 OutputStream. A FileConnection instance can have 
 only one InputStream and one OutputStream open at
 any one time. Trying to open more than one InputStream or more
 than one OutputStream from a StreamConnection 
 causes an IOException. Trying to open an InputStream
 or an OutputStream after the FileConnection has 
 been closed causes an IOException. 
 
 The inherited StreamConnection methods in a 
 FileConnection instance are not synchronized. The only stream 
 method that can be called safely from another thread is close. 
 When close is invoked on a stream that is executing in another 
 thread, any pending I/O method must throw an 
 InterruptedIOException. In the above case, implementations 
 should try to throw the exception in a timely manner. When all open streams 
 are closed and the FileConnection is closed, any
 pending I/O operations must be interrupted in a timely manner. 
 
 Data written to the output streams of these FileConnection 
 objects is not guaranteed to be flushed to the stream's destination 
 (and subsequently made available to any input streams) until either 
 flush() or close() is invoked on the stream. 
 
 Access to file connections is restricted to prevent unauthorized manipulation
 of data. The access security model applied to the file connection
 is defined by the implementing profile. The security model is applied on
 the invocation of the Connector.open() method with a valid file
 connection string. The mode provided in the open() method
 (Connector.READ_WRITE by default) indicates the application's
 request for access rights for the indicated file or directory and is
 therefore checked against the security scheme. All three connections modes
 (READ_WRITE, WRITE, and READ) are
 supported for a file connection and determine the access requested from the
 security model.
 
 The security model is also applied during use of the returned
 FileConnection, specifically when the methods
 openInputStream(), openDataInputStream(),
 openOutputStream(), and openDataOutputStream() are
 invoked. These methods have an implied request for access rights
 (input stream access requests read access, and output stream access
 requests write access).  If the application is not granted the
 appropriate read or write access to the file or file system by the profile
 authorization scheme, the  RuntimeException java.lang.SecurityException is thrown.
 
 File access through the File Connection API may be restricted to files that
 are within a public context and not deemed private or sensitive. This
 restriction is intended to protect the device's and other users' files and
 data from both malicious and unintentional access. RMS databases cannot be
 accessed using the File Connection API. Access to files and directories that
 are private to another application, files and directories that are private to
 a different user than the current user, system configuration files, and
 device and OS specific files and directories may be restricted. In these
 situations, a RuntimeException java.lang.SecurityException is thrown from the
 Connector.open() method if the file, file system, or directory
 cannot be accessed.
 
FileSystemRegistry| Method Summary | ||
|---|---|---|
 long | 
availableSize()
Determines the free memory that is available on the file system that the file or directory resides on.  | 
|
 boolean | 
canRead()
Checks if the file or directory is readable.  | 
|
 boolean | 
canWrite()
Checks if the file or directory is writable.  | 
|
 void | 
create()
Creates a file corresponding to the file string provided in the Connector.open() method for this FileConnection. | 
|
 void | 
delete()
Deletes the file or directory specified in the Connector.open() URL.  | 
|
 long | 
directorySize(boolean includeSubDirs)
Determines the size in bytes on a file system of all of the files that are contained in a directory.  | 
|
 boolean | 
exists()
Checks if the file or directory specified in the URL passed to the Connector.open() method exists.  | 
|
 long | 
fileSize()
Determines the size of a file on the file system.  | 
|
 String | 
getName()
Returns the name of a file or directory excluding the URL schema and all paths.  | 
|
 String | 
getPath()
Returns the path, excluding the file or directory name and the "file" URL schema and host from where the file or directory specified in the Connector.open() method is opened. | 
|
 String | 
getURL()
Returns the full file URL including the scheme, host, and path from where the file or directory specified in the Connector.open() method is opened.  | 
|
 boolean | 
isDirectory()
Checks if the URL passed to the Connector.open() is a directory.  | 
|
 boolean | 
isHidden()
Checks if the file is hidden.  | 
|
 boolean | 
isOpen()
Returns whether the file connection is currently open or not.  | 
|
 long | 
lastModified()
Returns the time that the file denoted by the URL specified in the Connector.open() method was last modified.  | 
|
 Enumeration | 
list()
Gets a list of all files and directories contained in a directory.  | 
|
 Enumeration | 
list(String filter,
     boolean includeHidden)
Gets a filtered list of files and directories contained in a directory.  | 
|
 void | 
mkdir()
Creates a directory corresponding to the directory string provided in the Connector.open() method. | 
|
 DataInputStream | 
openDataInputStream()
Opens and returns a data input stream for a connection.  | 
|
 DataOutputStream | 
openDataOutputStream()
Opens and returns a data output stream for a connection.  | 
|
 InputStream | 
openInputStream()
Opens and returns an input stream for a connection.  | 
|
 OutputStream | 
openOutputStream()
Opens and returns an output stream for a connection.  | 
|
 OutputStream | 
openOutputStream(long byteOffset)
Opens an output stream and positions it at the indicated byte offset in the file.  | 
|
 void | 
rename(String newName)
Renames the selected file or directory to a new name in the same directory.  | 
|
 void | 
setFileConnection(String fileName)
Resets this FileConnection object to another file or directory.  | 
|
 void | 
setHidden(boolean hidden)
Sets the hidden attribute of the selected file to the value provided.  | 
|
 void | 
setReadable(boolean readable)
Sets the file or directory readable attribute to the indicated value.  | 
|
 void | 
setWritable(boolean writable)
Sets the selected file or directory writable attribute to the indicated value.  | 
|
 long | 
totalSize()
Determines the total size of the file system the connection's target resides on.  | 
|
 void | 
truncate(long byteOffset)
Truncates the file, discarding all data from the given byte offset to the current end of the file.  | 
|
 long | 
usedSize()
Determines the used memory of the file system where the connection's target resides.  | 
|
| Methods inherited from interface javax.microedition.io.Connection | 
|---|
close | 
| Methods inherited from interface javax.microedition.io.Connection | 
|---|
close | 
| Method Detail | 
|---|
boolean isOpen()
true if the file connection is open; otherwise false.
InputStream openInputStream()
                            throws IOException
openInputStream in interface InputConnectionIOException - If an I/O error occurs, if the method is invoked on
          a directory, if the connection's target does not
          yet exist, or if the connection's target is not accessible.
IllegalModeException - If the application does have read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
SecurityException - If the application is not granted read
          access to the connection's target.
DataInputStream openDataInputStream()
                                    throws IOException
openDataInputStream in interface InputConnectionIOException - If an I/O error occurs, if the method is invoked on
          a directory, if the connection's target does not
          yet exist, or if the connection's target is not accessible.
IllegalModeException - If the application has read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
SecurityException - If the application is not granted read
          access to the connection's target.
OutputStream openOutputStream()
                              throws IOException
FileConnection.openOutputStream(long) should be used to position an output
 stream at a different position in the file.
 
 Changes made to a file through an output stream may not be immediately
 made to the actual file residing on the file system because
 platform and implementation specific use of caching and buffering of the
 data. Steam contents and file length extensions may not be immediately
 visible outside of the application unless
 flush() is called on the stream. The returned output stream
 is automatically and synchronously flushed when it is closed.
 
openOutputStream in interface OutputConnectionIOException - If an I/O error occurs, if the method is invoked on
          a directory, if the connection's target does not
          yet exist, or if the connection's target is not accessible.
IllegalModeException - If the application does have write access
          to the connection's target but has opened the connection in
          Connector.READ mode.
SecurityException - If the application is not granted write
          access to the connection's target.FileConnection.openOutputStream(long)
DataOutputStream openDataOutputStream()
                                      throws IOException
FileConnection.openOutputStream(long) should be used to position an output
 stream at a different position in the file.
 
 Changes made to a file through an output stream may not be immediately
 made to the actual file residing on the file system because
 platform and implementation specific use of caching and buffering of the
 data. Steam contents and file length extensions may not be
 immediately visible outside of the application unless
 flush() is called on the stream. The returned output stream
 is automatically and synchronously flushed when it is closed.
 
openDataOutputStream in interface OutputConnectionIOException - If an I/O error occurs, if the method is invoked on
          a directory, if the connection's target does not
          yet exist, or if the connection's target is not accessible.
IllegalModeException - If the application does have write access
          to the connection's target but has opened the connection in
          Connector.READ mode.
SecurityException - If the application is not granted write
          access to the connection's target.FileConnection.openOutputStream(long)
OutputStream openOutputStream(long byteOffset)
                              throws IOException
 Changes made to a file through an output stream may not be immediately
 made to the actual file residing on the file system because
 platform and implementation specific use of caching and buffering of the
 data. Steam contents and file length extensions are not necessarily
 visible outside of the application immediately unless
 flush() is called on the stream.  The returned output 
 stream is automatically and synchronously flushed when it is closed.
 
byteOffset - Number of bytes to skip over from the beginning of
          the file when positioning the start of the OutputStream. If 
          the provided offset is larger than or equal to the current file
          size, the OutputStream is positioned at the current end of the 
          file for appending.
IOException - If an I/O error occurs, if the method is invoked on
          a directory, if the connection's target does not
          yet exist, or if the connection's target is not accessible.
IllegalModeException - If the application does have write access
          to the connection's target but has opened the connection in
          Connector.READ mode.
SecurityException - If the security if the application does not
          allow write access to the file.
IllegalArgumentException - If byteOffset has a negative value.long totalSize()
SecurityException - If the security of the application does not
          have read access to the root volume.
IllegalModeException - If the application does have read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.long availableSize()
SecurityException - If the security of the application does not
          have read access to the root volume.
IllegalModeException - If the application does have read access
          to the directory but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.long usedSize()
SecurityException - If the security of the application does not
          have read access to the root volume.
IllegalModeException - If the application has read access
          to the directory but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.
long directorySize(boolean includeSubDirs)
                   throws IOException
includeSubdirs - If set to true, the method determines
                       the size of the given directory and all subdirectories
                       recursively. If false, the method returns the size
                       of the files in the directory only.
IOException - If the method is invoked on a file.
SecurityException - If the security of the application does not
          have read access for the directory.
IllegalModeException - If the application has read access
          to the directory but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.
long fileSize()
              throws IOException
 fileSize() always returns size of the file on the file system, 
 and not in any pending output stream. flush() should be used 
 before calling fileSize() to ensure the contents 
 of the output streams opened to the file get written to the file system.
IOException - If the method is invoked on a directory.
SecurityException - If the security of the application does not
          have read access for the file.
IllegalModeException - If the application has read access
          to the file but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.boolean canRead()
true.
true if the connection's target exists, is accessible, and 
          is readable; otherwise false.
SecurityException - If the security of the application does not
          have read access for the connection's target.
IllegalModeException - If the application has read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.FileConnection.setReadable(boolean)boolean canWrite()
true.
true if the connection's target exists, is accessible, and 
          is writable; otherwise false.
SecurityException - If the security of the application does not
          have read access for the connection's target.
IllegalModeException - If the application has read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.FileConnection.setWritable(boolean)boolean isHidden()
false.
true if the file exists, is accessible, and is hidden, 
          otherwise false.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have read access for the connection's target.
IllegalModeException - If the application has read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.FileConnection.setHidden(boolean)
void setReadable(boolean readable)
                 throws IOException
canRead() always returns true.
readable - The new state of the readable flag of the selected file.
IOException - If the connection's target does not exist or is not
          accessible.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have write access to the connection's target.
IllegalModeException - If the application has write access
          to the connection's target but has opened the connection in
          Connector.READ mode.FileConnection.canRead()
void setWritable(boolean writable)
                 throws IOException
canWrite() always returns true.
writable - The new state of the writable flag of the selected file.
IOException - If the connection's target does not exist or is not
          accessible.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have write access to the connection's target.
IllegalModeException - If the application has write access
          to the connection's target but has opened the connection in
          Connector.READ mode.FileConnection.canWrite()
void setHidden(boolean hidden)
               throws IOException
isHidden() always
 returns false. Since the exact definition of hidden is system-dependent,
 this method only works on file systems that support a settable file
 attribute. For example, on Win32 and FAT file systems, a file may be
 considered hidden if it has been marked as such in the file's
 attributes; therefore this method is applicable. However on UNIX
 systems a file may be considered to be hidden if its name begins with a
 period character (.). In the UNIX case, this method can be ignored; to make a file hidden,
 use the rename() method.
hidden - The new state of the hidden flag of the selected file.
IOException - If the connection's target does not exist or is not
          accessible.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have write access to the connection's target.
IllegalModeException - If the application has write access
          to the connection's target but has opened the connection in
          Connector.READ mode.FileConnection.isHidden()
Enumeration list()
                 throws IOException
Connector.open().
FileConnection.getPath().) Directories are denoted with a
          trailing slash (/) in their returned name.  The Enumeration has
          zero length if the directory is empty. Any
          hidden files and directories in the directory are not included
          in the returned list. Any current or parent directory indication ("." or "..")
          is not included
          in the list of files and directories that is returned.
IOException - If invoked on a file and the directory does not exist,
          the directory is not accessible, or an I/O error occurs.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have read access for the directory.
IllegalModeException - If the application has read access
          to the directory but has opened the connection in
          Connector.WRITE mode.
Enumeration list(String filter,
                 boolean includeHidden)
                 throws IOException
Connector.open().
filter - String against which all files and directories are
          matched for retrieval. An asterisk (*) can be used as a
          wildcard to represent zero or more occurrences of any character.includeHidden - Boolean indicating whether files that are marked as hidden
          should be included or not in the list of files and directories that is
          returned.
IOException - If invoked on a file, the directory does not exist,
          the directory is not accessible, or an I/O error occurs.
ConnectionClosedException - If the connection is closed.
SecurityException - if the security of the application does not
          have read access for the directory.
IllegalModeException - If the application does have read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
NullPointerException - If filter is
          null.
IllegalArgumentException - If a filter contains any path 
          specification or is an invalid filename for the platform.
void create()
            throws IOException
Connector.open() method for this FileConnection. The
 Upon invocation of this method, the file is created immediately on the actual file system.
 Files are created with zero length and data can be put into
 the file through output streams opened on the file. This method does not
 create any directories specified in the file's path.
SecurityException - If the security of the application does not
          have write access for the file.
IllegalModeException - If the application does have write access
          to the file but has opened the connection in
          Connector.READ mode.
IOException - If invoked on an existing file or on any directory
          (mkdir() is used to create directories), the
          connection's target has a trailing slash (/) to denote a 
          directory, the target file system is not accessible, or an
          unspecified error occurs preventing creation of the file.
ConnectionClosedException - If the connection is closed.
void mkdir()
           throws IOException
Connector.open() method.
 Upon invocation of this method, the directory is created immediately on the actual
 file system. Directories in the 
 specified path are not recursively created and must be explicitly 
 created before subdirectories can be created.
SecurityException - If the security of the application does not
          have write access to the directory.
IllegalModeException - If the application does have write access
          to the directory but has opened the connection in
          Connector.READ mode.
IOException - If invoked on an existing directory or on any file
          (create() is used to create files), the target
          file sytem is not accessible, or an unspecified error occurs 
          preventing creation of the directory.
ConnectionClosedException - If the connection is closed.boolean exists()
true if the connnection's target exists and is accessible, 
          otherwise false.
SecurityException - If the security of the application does not
          have read access for the connection's target.
IllegalModeException - If the application has read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.boolean isDirectory()
true if the connection's target exists, is accessible, and 
          is a directory; otherwise false.
SecurityException - If the security of the application does not
          have read access for the connection's target.
ConnectionClosedException - If the connection is closed.
IllegalModeException - If the application has read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
void delete()
            throws IOException
IOException. The
 FileConnection instance object remains open and available for use.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have write access to the connection's target.
IllegalModeException - If the application does have write access
          to the connection's target but has opened the connection in
          Connector.READ mode.
IOException - If the target is a directory and it is not empty,
          the connection target does not exist or is unaccessible, or
          an unspecified error occurs preventing deletion of the target.
void rename(String newName)
            throws IOException
IOException. The
 FileConnection instance object remains open and available for use,
 referring now to the file or directory by its new name.
newName - The new name of the file or directory. The name must
          not contain any path specification; the file or directory
          remains in its same directory as before this method call.
IOException - If the connection's target does not exist, the 
          connection's target is not accessible, a file or directory 
          already exists by the newName, or 
          newName is an invalid filename for the platform.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have write access to the connection's target.
IllegalModeException - If the application has write access
          to the connection's target but has opened the connection in
          Connector.READ mode.
NullPointerException - If newName is
          null.
IllegalArgumentException - If newName contains any
          path specification.
void truncate(long byteOffset)
              throws IOException
byteOffset - The offset into the file from which truncation 
          occurs.
IOException - If invoked on a directory or the file does not exist
          or is not accessible.
ConnectionClosedException - If the connection is closed.
SecurityException - If the security of the application does not
          have write access to the file.
IllegalModeException - If the application does have write access
          to the file but has opened the connection in
          Connector.READ mode.
IllegalArgumentException - If byteOffset is
          less than zero.
void setFileConnection(String fileName)
                       throws IOException
fileName - The name of the file or directory to which this
          FileConnection is reset. The fileName must be one of the
          values returned from the FileConnection.list() method, or the string
          ".." to indicate the parent directory of the current
          connection. The fileName must not contain any additional path 
          specification; i.e. the file or directory must reside within 
          the current directory.
NullPointerException - If fileName is
          null.
SecurityException - If the security of the application does not
          have the security access to the specified file or directory
          as requested in the Connector.open method
          invocation that originally opened this FileConnection.
IllegalArgumentException - If fileName contains any
          path specification or does not yet exist.
IOException - If the current FileConnection is opened on a file,
          the connection's target is not accessible, or
          fileName is an invalid filename for the platform
          (e.g. contains characters invalid in a filename on the platform), or 
          the current connection is connected to the file system's root and 
          the fileName parameter is "..".
ConnectionClosedException - if the connection is closed.String getName()
<directory>/or
<filename.extension>or if no file extension
<filename>
String getPath()
Connector.open() method is opened. FileConnection.getName() can be appended to
 this value to get a fully qualified path filename. The String resulting
 from this method looks as follows:
 /<root>/<directory>/
String getURL()
file://<host>/<root>/<directory>/<filename.extension>or
file://<host>/<root>/<directory>/<directoryname>/
long lastModified()
0L if an I/O error occurs.
          If modification date is not supported by the underlying platform
          and/or file system, then 0L is also returned.
          If the connection's target does not exist or is not
          accessible, 0L is returned.
SecurityException - If the security of the application does not
          have read access for the connection's target.
IllegalModeException - If the application does have read access
          to the connection's target but has opened the connection in
          Connector.WRITE mode.
ConnectionClosedException - If the connection is closed.
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2011 Research In Motion Limited.  295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8.  All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal