📄 fileconnection.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<TITLE>FileConnection (FileConnection Optional Package 1.0 Spec, Final Release) </TITLE>
<!-- Generated by javadoc on Wed Oct 29 13:12:43 PST 2003 -->
<META NAME="keywords" CONTENT="javax.microedition.io.file.FileConnection,FileConnection interface">
<LINK REL="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<SCRIPT>
function asd()
{
parent.document.title="FileConnection (FileConnection Optional Package 1.0 Spec, Final Release)";
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="asd();">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN="3" BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#ffffff" CLASS="NavBarCell1Rev">
<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#eeeeff" CLASS="NavBarCell1">
<A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN="3"><EM> FileConnection Optional Package 1.0<br>
Final Release</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> PREV CLASS <A HREF="../../../../javax/microedition/io/file/FileSystemListener.html"><B>NEXT
CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../index.html" TARGET="_top">
<B>FRAMES</B></A> <A HREF="FileConnection.html" TARGET="_top"><B>NO
FRAMES</B></A>
<SCRIPT> <!-- if(window==top) { document.writeln('<A HREF="../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--></SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
</NOSCRIPT>
</FONT>
</TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">javax.microedition.io.file</FONT>
<BR>
Interface FileConnection</H2>
<DL>
<DT><B>All Superinterfaces:</B>
<DD>
javax.microedition.io.Connection, javax.microedition.io.InputConnection,
javax.microedition.io.OutputConnection, javax.microedition.io.StreamConnection</DD>
</DL>
<HR>
<DL>
<DT>public interface <B>FileConnection</B><DT>extends
javax.microedition.io.StreamConnection</DT></DL>
<P>
This interface is intended to access files or directories that are located on
removeable media and/or file systems on a device.
<P>
Device internal filesystems in memory may also be accessed through this class
as well, provided there is underlying hardware and OS support. If file
connections are not supported to a particular media or file system, attempts to
open a file connection to the media or file system through <code>Connector.open()</code>
results in an <code>javax.microedition.io.IOException</code> being thrown.
</P>
<H2>Establishing a Connection</H2>
<P>The format of the input string used to access a FileConnection through <code>Connector.open()</code>
must follow the format of a fully-qualified, absolute path file name as
described by the file URL format in IETF RFCs 1738 & 2396. Further detail
for the File URL format can be found in the javax.microedition.io.file package
description.
</P>
<p>A single connection object only references a single file or directory at a time.
In some cases, a connection object can be reused to refer to a different file
or directory than it was originally associated with (see <A HREF="../../../../javax/microedition/io/file/FileConnection.html#setFileConnection(java.lang.String)">
<CODE>setFileConnection(java.lang.String)</CODE></A>). In general, the best
approach to reference a different file or directory is by establishing a
completely separate connection through the <code>Connector.open()</code> method.</p>
<H2>FileConnection Behavior</H2>
<p>File connection is different from other Generic Connection Framework connections
in that a connection object can be successfully returned from the <code>Connector.open()</code>
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 <I>CFCard</I> is a valid existing file system root name
for a given implementation:</p>
<code>
<pre>
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) {
}</pre>
</code>
<p>
Developers should always check for the file's or directory's existence after a
connection is established to determine if the file or directory actually
exists. Similarly, files or directories can be deleted using the <A HREF="../../../../javax/microedition/io/file/FileConnection.html#delete()">
<CODE>delete()</CODE></A> method, and developers should close the
connection immediately after deletion to prevent exceptions from accessing a
connection to a non-existent file or directory.
</p>
<P>
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 <code>close()</code> is invoked on the FileConnection instance.
Input and output streams may be opened and closed multiple times on a
FileConnection instance.
</P>
<p>
All <code>FileConnection</code> instances have one underlying <code>InputStream</code>
and one <code>OutputStream</code>. Opening a <code>DataInputStream</code> counts
as opening an <code>InputStream,</code> and opening a <code>DataOutputStream</code>
counts as opening an <code>OutputStream</code>. A <code>FileConnection</code> instance
can have only one <code>InputStream</code> and one <code>OutputStream</code> open
at any one time. Trying to open more than one <code>InputStream</code> or more
than one <code>OutputStream</code> from a <code>StreamConnection</code> causes
an <code>IOException</code>. Trying to open an <code>InputStream</code> or an <code>
OutputStream</code> after the <code>FileConnection</code> has been closed
causes an <code>IOException</code>.
</p>
<p>
The inherited <code>StreamConnection</code> methods in a <code>FileConnection</code>
instance are not synchronized. The only stream method that can be called safely
from another thread is <code>close</code>. When <code>close</code> is invoked
on a stream that is executing in another thread, any pending I/O method MUST
throw an <code>InterruptedIOException</code>. In the above case,
implementations SHOULD try to throw the exception in a timely manner. When all
open streams have been closed, and when the <code>FileConnection</code> is
closed, any pending I/O operations MUST be interrupted in a timely manner.
</p>
<p>
Data written to the output streams of these <code>FileConnection</code> objects
is not guaranteed to be flushed to the stream's destination (and subsequently
made available to any input streams) until either <code>flush()</code> or <code>close()</code>
is invoked on the stream.
</p>
<h2>Security</h2>
<P>
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 <code>Connector.open()</code> method with a valid file connection string.
The mode provided in the <code>open()</code> method (<code>Connector.READ_WRITE</code>
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 (<code>READ_WRITE, WRITE_ONLY,</code> and <code>
READ_ONLY</code>) are supported for a file connection and determine the
access requested from the security model.
</P>
<P>
The security model is also applied during use of the returned FileConnection,
specifically when the methods <code>openInputStream()</code>, <code>openDataInputStream()</code>,
<code>openOutputStream()</code>, and <code>openDataOutputStream()</code> are
invoked. These methods have implied request for access rights (i.e. input
stream access is requesting read access, and output stream access is requesting
write access). Should the application not be granted the appropriate read or
write access to the file or file system by the profile authorization scheme, a <code>
java.lang.SecurityException</code> is thrown.
</P>
<P>
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 <code>java.lang.SecurityException</code>
is thrown from the <code>Connector.open()</code> method if the file, file
system, or directory is not allowed to be accessed.
</P>
<P>
<P>
<DL>
<DT><B>Since:</B>
<DD>
FileConnection 1.0 <DT><B>See Also:</B><DD><A HREF="../../../../javax/microedition/io/file/FileSystemRegistry.html"><CODE>FileSystemRegistry</CODE></A></DD></DL>
<HR>
<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#ccccff" CLASS="TableHeadingColor">
<TD COLSPAN="2"><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../javax/microedition/io/file/FileConnection.html#availableSize()">availableSize</A></B>()</CODE>
<BR>
Determines the free
memory that is available on the file system the file or directory resides on.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../javax/microedition/io/file/FileConnection.html#canRead()">canRead</A></B>()</CODE>
<BR>
Checks if the file
or directory is readable.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../javax/microedition/io/file/FileConnection.html#canWrite()">canWrite</A></B>()</CODE>
<BR>
Checks if the file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -