< prev index next >

src/java.base/share/classes/java/nio/channels/FileChannel.java

Print this page




 160      * Initializes a new instance of this class.
 161      */
 162     protected FileChannel() { }
 163 
 164     /**
 165      * Opens or creates a file, returning a file channel to access the file.
 166      *
 167      * <p> The {@code options} parameter determines how the file is opened.
 168      * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE
 169      * WRITE} options determine if the file should be opened for reading and/or
 170      * writing. If neither option (or the {@link StandardOpenOption#APPEND APPEND}
 171      * option) is contained in the array then the file is opened for reading.
 172      * By default reading or writing commences at the beginning of the file.
 173      *
 174      * <p> In the addition to {@code READ} and {@code WRITE}, the following
 175      * options may be present:
 176      *
 177      * <table class="striped">
 178      * <caption style="display:none">additional options</caption>
 179      * <thead>
 180      * <tr> <th>Option</th> <th>Description</th> </tr>
 181      * </thead>
 182      * <tbody>
 183      * <tr>
 184      *   <td> {@link StandardOpenOption#APPEND APPEND} </td>
 185      *   <td> If this option is present then the file is opened for writing and
 186      *     each invocation of the channel's {@code write} method first advances
 187      *     the position to the end of the file and then writes the requested
 188      *     data. Whether the advancement of the position and the writing of the
 189      *     data are done in a single atomic operation is system-dependent and
 190      *     therefore unspecified. This option may not be used in conjunction
 191      *     with the {@code READ} or {@code TRUNCATE_EXISTING} options. </td>
 192      * </tr>
 193      * <tr>
 194      *   <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td>
 195      *   <td> If this option is present then the existing file is truncated to
 196      *   a size of 0 bytes. This option is ignored when the file is opened only
 197      *   for reading. </td>
 198      * </tr>
 199      * <tr>
 200      *   <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td>
 201      *   <td> If this option is present then a new file is created, failing if
 202      *   the file already exists. When creating a file the check for the
 203      *   existence of the file and the creation of the file if it does not exist
 204      *   is atomic with respect to other file system operations. This option is
 205      *   ignored when the file is opened only for reading. </td>
 206      * </tr>
 207      * <tr>
 208      *   <td > {@link StandardOpenOption#CREATE CREATE} </td>
 209      *   <td> If this option is present then an existing file is opened if it
 210      *   exists, otherwise a new file is created. When creating a file the check
 211      *   for the existence of the file and the creation of the file if it does
 212      *   not exist is atomic with respect to other file system operations. This
 213      *   option is ignored if the {@code CREATE_NEW} option is also present or
 214      *   the file is opened only for reading. </td>
 215      * </tr>
 216      * <tr>
 217      *   <td > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </td>
 218      *   <td> When this option is present then the implementation makes a
 219      *   <em>best effort</em> attempt to delete the file when closed by the
 220      *   the {@link #close close} method. If the {@code close} method is not
 221      *   invoked then a <em>best effort</em> attempt is made to delete the file
 222      *   when the Java virtual machine terminates. </td>
 223      * </tr>
 224      * <tr>
 225      *   <td>{@link StandardOpenOption#SPARSE SPARSE} </td>
 226      *   <td> When creating a new file this option is a <em>hint</em> that the
 227      *   new file will be sparse. This option is ignored when not creating
 228      *   a new file. </td>
 229      * </tr>
 230      * <tr>
 231      *   <td> {@link StandardOpenOption#SYNC SYNC} </td>
 232      *   <td> Requires that every update to the file's content or metadata be
 233      *   written synchronously to the underlying storage device. (see <a
 234      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 235      *   integrity</a>). </td>
 236      * </tr>
 237      * <tr>
 238      *   <td> {@link StandardOpenOption#DSYNC DSYNC} </td>
 239      *   <td> Requires that every update to the file's content be written
 240      *   synchronously to the underlying storage device. (see <a
 241      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 242      *   integrity</a>). </td>
 243      * </tr>
 244      * </tbody>
 245      * </table>
 246      *
 247      * <p> An implementation may also support additional options.
 248      *
 249      * <p> The {@code attrs} parameter is an optional array of file {@link
 250      * FileAttribute file-attributes} to set atomically when creating the file.
 251      *
 252      * <p> The new channel is created by invoking the {@link
 253      * FileSystemProvider#newFileChannel newFileChannel} method on the
 254      * provider that created the {@code Path}.
 255      *
 256      * @param   path
 257      *          The path of the file to open or create
 258      * @param   options




 160      * Initializes a new instance of this class.
 161      */
 162     protected FileChannel() { }
 163 
 164     /**
 165      * Opens or creates a file, returning a file channel to access the file.
 166      *
 167      * <p> The {@code options} parameter determines how the file is opened.
 168      * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE
 169      * WRITE} options determine if the file should be opened for reading and/or
 170      * writing. If neither option (or the {@link StandardOpenOption#APPEND APPEND}
 171      * option) is contained in the array then the file is opened for reading.
 172      * By default reading or writing commences at the beginning of the file.
 173      *
 174      * <p> In the addition to {@code READ} and {@code WRITE}, the following
 175      * options may be present:
 176      *
 177      * <table class="striped">
 178      * <caption style="display:none">additional options</caption>
 179      * <thead>
 180      * <tr> <th scope="col">Option</th> <th scope="col">Description</th> </tr>
 181      * </thead>
 182      * <tbody>
 183      * <tr>
 184      *   <th scope="row"> {@link StandardOpenOption#APPEND APPEND} </th>
 185      *   <td> If this option is present then the file is opened for writing and
 186      *     each invocation of the channel's {@code write} method first advances
 187      *     the position to the end of the file and then writes the requested
 188      *     data. Whether the advancement of the position and the writing of the
 189      *     data are done in a single atomic operation is system-dependent and
 190      *     therefore unspecified. This option may not be used in conjunction
 191      *     with the {@code READ} or {@code TRUNCATE_EXISTING} options. </td>
 192      * </tr>
 193      * <tr>
 194      *   <th scope="row"> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </th>
 195      *   <td> If this option is present then the existing file is truncated to
 196      *   a size of 0 bytes. This option is ignored when the file is opened only
 197      *   for reading. </td>
 198      * </tr>
 199      * <tr>
 200      *   <th scope="row"> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </th>
 201      *   <td> If this option is present then a new file is created, failing if
 202      *   the file already exists. When creating a file the check for the
 203      *   existence of the file and the creation of the file if it does not exist
 204      *   is atomic with respect to other file system operations. This option is
 205      *   ignored when the file is opened only for reading. </td>
 206      * </tr>
 207      * <tr>
 208      *   <th scope="row" > {@link StandardOpenOption#CREATE CREATE} </th>
 209      *   <td> If this option is present then an existing file is opened if it
 210      *   exists, otherwise a new file is created. When creating a file the check
 211      *   for the existence of the file and the creation of the file if it does
 212      *   not exist is atomic with respect to other file system operations. This
 213      *   option is ignored if the {@code CREATE_NEW} option is also present or
 214      *   the file is opened only for reading. </td>
 215      * </tr>
 216      * <tr>
 217      *   <th scope="row" > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </th>
 218      *   <td> When this option is present then the implementation makes a
 219      *   <em>best effort</em> attempt to delete the file when closed by the
 220      *   the {@link #close close} method. If the {@code close} method is not
 221      *   invoked then a <em>best effort</em> attempt is made to delete the file
 222      *   when the Java virtual machine terminates. </td>
 223      * </tr>
 224      * <tr>
 225      *   <th scope="row">{@link StandardOpenOption#SPARSE SPARSE} </th>
 226      *   <td> When creating a new file this option is a <em>hint</em> that the
 227      *   new file will be sparse. This option is ignored when not creating
 228      *   a new file. </td>
 229      * </tr>
 230      * <tr>
 231      *   <th scope="row"> {@link StandardOpenOption#SYNC SYNC} </th>
 232      *   <td> Requires that every update to the file's content or metadata be
 233      *   written synchronously to the underlying storage device. (see <a
 234      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 235      *   integrity</a>). </td>
 236      * </tr>
 237      * <tr>
 238      *   <th scope="row"> {@link StandardOpenOption#DSYNC DSYNC} </th>
 239      *   <td> Requires that every update to the file's content be written
 240      *   synchronously to the underlying storage device. (see <a
 241      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 242      *   integrity</a>). </td>
 243      * </tr>
 244      * </tbody>
 245      * </table>
 246      *
 247      * <p> An implementation may also support additional options.
 248      *
 249      * <p> The {@code attrs} parameter is an optional array of file {@link
 250      * FileAttribute file-attributes} to set atomically when creating the file.
 251      *
 252      * <p> The new channel is created by invoking the {@link
 253      * FileSystemProvider#newFileChannel newFileChannel} method on the
 254      * provider that created the {@code Path}.
 255      *
 256      * @param   path
 257      *          The path of the file to open or create
 258      * @param   options


< prev index next >