JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the FileStream Class

As discussed in the In Depth section of this chapter, you can use the FileStream class to open or create files, and then use other classes, like BinaryWriter and BinaryReader, to work with the data in the file. Here's the hierarchy of the FileStream class:

Object
   MarshalByRefObject
      Stream
         FileStream

You can find the more notable public properties of FileStream objects in Table 13.7 and the more notable public methods in Table 13.8.

Table 13.7: Noteworthy public properties of FileStream objects.

Property

Means

CanRead

Determines if the stream supports reading.

CanSeek

Determines if the stream supports seeking.

CanWrite

Determines if the stream supports writing.

Handle

Gets the operating system file handle for the stream's file.

IsAsync

Determines if the stream was opened asynchronously or synchronously.

Length

Gets the length of the stream in bytes.

Name

Gets the name of the file stream passed to the constructor.

Position

Gets/sets the position in this stream.

Table 13.8: Noteworthy public methods of FileStream objects.

Method

Means

BeginRead

Starts an asynchronous read operation.

BeginWrite

Starts an asynchronous write operation.

Close

Closes a file, making it available in Windows to any other program.

EndRead

Waits for an asynchronous read operation to finish.

EndWrite

Ends an asynchronous write operation, waiting until the operation has finished.

Flush

Flushes all buffers for this stream, writing any buffered data out to its target (such as a disk file).

Lock

Withholds any access to the file to other processes.

Read

Reads a block of bytes.

ReadByte

Reads a byte from the file.

Seek

Sets the current read/write position.

SetLength

Sets the length of the stream.

Unlock

Gives access to other processes to a file that had been locked.

Write

Writes a block of bytes to this stream.

WriteByte

Writes a byte to the current read/write position.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor