Udostępnij za pośrednictwem


RandomAccessFile Constructors

Definition

Overloads

RandomAccessFile(File, String)

Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.

RandomAccessFile(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

RandomAccessFile(String, String)

Creates a random access file stream to read from, and optionally to write to, a file with the specified name.

RandomAccessFile(File, String)

Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.

[Android.Runtime.Register(".ctor", "(Ljava/io/File;Ljava/lang/String;)V", "")]
public RandomAccessFile (Java.IO.File? file, string? mode);
[<Android.Runtime.Register(".ctor", "(Ljava/io/File;Ljava/lang/String;)V", "")>]
new Java.IO.RandomAccessFile : Java.IO.File * string -> Java.IO.RandomAccessFile

Parameters

file
File

the file object

mode
String

the access mode, as described above

Attributes

Exceptions

if the file cannot be opened or created according to mode.

if mode is not "r", "rw", "rws" or "rwd".

Remarks

Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument. A new FileDescriptor object is created to represent this file connection.

The "mode"><c>mode</c> argument specifies the access mode in which the file is to be opened. The permitted values and their meanings are:

<table summary="Access mode permitted values and meanings"> <tr><th align="left">Value</th><th align="left">Meaning</th></tr> <tr><td valign="top">"r"</td> <td> Open for reading only. Invoking any of the write methods of the resulting object will cause an java.io.IOException to be thrown. </td></tr> <tr><td valign="top">"rw"</td> <td> Open for reading and writing. If the file does not already exist then an attempt will be made to create it. </td></tr> <tr><td valign="top">"rws"</td> <td> Open for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the underlying storage device. </td></tr> <tr><td valign="top">"rwd"&nbsp;&nbsp;</td> <td> Open for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying storage device. </td></tr> </table>

The "rws" and "rwd" modes work much like the java.nio.channels.FileChannel#force(boolean) force(boolean) method of the java.nio.channels.FileChannel class, passing arguments of true and false, respectively, except that they always apply to every I/O operation and are therefore often more efficient. If the file resides on a local storage device then when an invocation of a method of this class returns it is guaranteed that all changes made to the file by that invocation will have been written to that device. This is useful for ensuring that critical information is not lost in the event of a system crash. If the file does not reside on a local device then no such guarantee is made.

The "rwd" mode can be used to reduce the number of I/O operations performed. Using "rwd" only requires updates to the file's content to be written to storage; using "rws" requires updates to both the file's content and its metadata to be written, which generally requires at least one more low-level I/O operation.

If there is a security manager, its checkRead method is called with the pathname of the file argument as its argument to see if read access to the file is allowed. If the mode allows writing, the security manager's checkWrite method is also called with the path argument to see if write access to the file is allowed.

Java documentation for java.io.RandomAccessFile.RandomAccessFile(java.io.File, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

RandomAccessFile(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

protected RandomAccessFile (IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer);
new Java.IO.RandomAccessFile : nativeint * Android.Runtime.JniHandleOwnership -> Java.IO.RandomAccessFile

Parameters

javaReference
IntPtr

nativeint

A IntPtrcontaining a Java Native Interface (JNI) object reference.

transfer
JniHandleOwnership

A JniHandleOwnershipindicating how to handle javaReference

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

RandomAccessFile(String, String)

Creates a random access file stream to read from, and optionally to write to, a file with the specified name.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;)V", "")]
public RandomAccessFile (string? name, string? mode);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;)V", "")>]
new Java.IO.RandomAccessFile : string * string -> Java.IO.RandomAccessFile

Parameters

name
String

the system-dependent filename

mode
String

the access mode

Attributes

Exceptions

if the file cannot be opened or created according to mode.

if mode is not "r", "rw", "rws" or "rwd".

Remarks

Creates a random access file stream to read from, and optionally to write to, a file with the specified name. A new FileDescriptor object is created to represent the connection to the file.

The mode argument specifies the access mode with which the file is to be opened. The permitted values and their meanings are as specified for the <c>RandomAccessFile(File,String)</c> constructor.

If there is a security manager, its checkRead method is called with the name argument as its argument to see if read access to the file is allowed. If the mode allows writing, the security manager's checkWrite method is also called with the name argument as its argument to see if write access to the file is allowed.

Java documentation for java.io.RandomAccessFile.RandomAccessFile(java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to