Advanced   Java   Services FileStream Back Next Up Home

FileStream

Use the FileStream class to read from, write to, open, and close files on a file system, as well as to manipulate other file-related operating system handles including pipes, standard input, and standard output. You can specify read and write operations to be either synchronous or asynchronous. FileStream buffers input and output for better performance.

FileStream objects support random access to files using the Seek method. Seek allows the read/write position to be moved to any position within the file. This is done with byte offset reference point parameters. The byte offset is relative to the seek reference point, which can be the beginning, the current position, or the end of the underlying file, as represented by the three properties of the SeekOrigin class.

Note: Disk files always support random access. At the time of construction, the CanSeek property value is set to true or false depending on the underlying file type. Specifically, if the underlying file type is FILE_TYPE_DISK, as defined in winbase.h, the CanSeek property value is true. Otherwise, the CanSeek property value is false.

Although the synchronous methods Read and Write and the asynchronous methods BeginRead, BeginWrite, EndRead, and EndWrite can work in either synchronous or asynchronous mode, the mode affects the performance of these methods. FileStream defaults to opening files synchronously, but provides the FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) constructor to open files asynchronously.

If a process terminates with part of a file locked or closes a file that has outstanding locks, the behavior is undefined.

Be sure to call the Dispose method on all FileStream objects, especially in environments with limited disk space. Performing IO operations can raise an exception if there is no disk space available and the Dispose method is not called before the FileStream is finalized.

For directory and other file operations, see the File, Directory, and Path classes. The File class is a utility class with static methods primarily for the creation of FileStream objects based on file paths and the standard input, standard output, and standard error devices. The MemoryStream class creates a stream from a byte array and functions similarly to a FileStream.

Einige Konstruktoren
public FileStream(String path, FileMode mode) Initializes a new instance of the FileStream class with the specified path and creation mode.
public FileStream(String path, FileMode mode, FileAccess access) Initializes a new instance of the FileStream class with the specified path, creation mode, and read/write permission.
public FileStream(String path, FileMode mode, FileAccess access, FileShare share) Initializes a new instance of the FileStream class with the specified path, creation mode, read/write permission, and sharing permission.
public K_Name desc
Einige Methoden
Returntyp Name der Methode
void Xxx()
xxx
void Xxx()
xxx
void Xxx()
xxx
Einige Properties
Typ Name
typ prop
desc


Die Enums FileMode, FileAccess und FileShare
public enum System.IO.FileMode
CreateNew Specifies that the operating system should create a new file. This requires FileIOPermissionAccess..::.Write. If the file already exists, an IOException is thrown.
Name description
Name description
Name description
Name description

public enum System.IO.FileAccess
Read Read access to the file. Data can be read from the file. Combine with Write for read/write access.
Write Write access to the file. Data can be written to the file. Combine with Read for read/write access.
ReadWrite Read and write access to the file. Data can be written to and read from the file.

public enum System.IO.FileShare
Name description
Name description

Codebeispiel 1







Valid XHTML 1.0 Strict top Back Next Up Home