📄 fileconnection.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Mon Feb 10 18:17:36 PST 2003 -->
<TITLE>
FileConnection (FileConnection Optional Package 1.0 Spec, Proposed Final Draft)
</TITLE>
<META NAME="keywords" CONTENT="javax.microedition.io.file.FileConnection,FileConnection interface">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
</HEAD>
<SCRIPT>
function asd()
{
parent.document.title="FileConnection (FileConnection Optional Package 1.0 Spec, Proposed Final Draft)";
}
</SCRIPT>
<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="../../../../overview-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>Proposed Final Draft</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</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 RAM or ROM 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> will result in an <code>javax.microedition.io.IOException</code> being thrown. </P> <H2>Establishing a Connection</H2> <P>The format of the Connector.open() input string used to access a FileConnection must follow the format described in the file URL format as part of IETF RFCs 1738 & 2396. That RFC dictates that a file URL takes the form: </P> <code>file://<host>/<path> </code> <P>In the form above, <host> is the fully qualified domain name of the system on which the <path> is accessible, and <path> is a hierarchical directory path of the form <code><root>/<directory>/<directory>/.../<name></code>. </P> <P> The file connection defines the first directory as the <I>root</I>, which corresponds to a logical mount point for a particular storage unit or memory. The root of a file system supporting only one card reader may return the contents of the card directly. If more than one card reader is supported or the device supports a file system in RAM, the root strings are device specific. Since the roots are part of the path string as a directory, they have a trailing "/". Examples of possible root strings include: <pre> CFCard/ SDCard/ MemoryStick/ C:/ / </pre> <P> The valid <root> values for a device can be retrieved by using the <A HREF="../../../../javax/microedition/io/file/FileSystemRegistry.html#listRoots()"><CODE>FileSystemRegistry.listRoots()</CODE></A> method. </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>Connection Behaviors</H2> <p>The file connection API is different from other Generic Connection Framework APIs in that a connection object can be successfully returned from the <code>Connector.open()</code> method without actually referencing an existing file or directory. This method is used to allow 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:</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> An <code>IOException</code> is thrown when opening an input stream on a nonexistent file. Opening an output stream on a nonexistent file automatically creates that file with a length of zero. Attempts to open any stream on a connection to a directory results in an <code>IOException</code>. </P> <P> Changes made to a file or directory using the FileConnection methods <code>create(), delete(), mkdir(), rename(), setHidden(), setReadable(), and setWritable()</code> are made immediately upon invocation of the method and become visible to other FileConnection instances open to the same file or directory. The same cannot be said about input and output streams opened on a file because of caching and buffering of the data. Buffering in streams may occur and is implementation-specific. Contents and file length extensions are not necessarily visible outside of the application immediately unless <code>flush()</code> is called on the stream.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -