FileStream.SetLength(Int64) Metodo
Definizione
Imposta la lunghezza del flusso sul valore dato.Sets the length of this stream to the given value.
public:
override void SetLength(long value);
public override void SetLength (long value);
override this.SetLength : int64 -> unit
Public Overrides Sub SetLength (value As Long)
Parametri
- value
- Int64
Nuova lunghezza del flusso.The new length of the stream.
Eccezioni
Si è verificato un errore di I/O.An I/O error has occurred.
Il flusso non supporta né la scrittura né la ricerca.The stream does not support both writing and seeking.
Si è provato a impostare il parametro value
su un valore minore di 0.Attempted to set the value
parameter to less than 0.
Commenti
Questo metodo esegue l'override di SetLength.This method overrides SetLength.
Se il valore specificato è minore della lunghezza corrente del flusso, il flusso viene troncato.If the given value is less than the current length of the stream, the stream is truncated. In questo scenario, se la posizione corrente è maggiore della nuova lunghezza, la posizione corrente viene spostata nell'ultimo byte del flusso.In this scenario, if the current position is greater than the new length, the current position is moved to the last byte of the stream. Se il valore specificato è maggiore della lunghezza corrente del flusso, il flusso viene espanso e la posizione corrente rimane invariata.If the given value is larger than the current length of the stream, the stream is expanded, and the current position remains the same. Se il flusso è espanso, il contenuto del flusso tra la vecchia e la nuova lunghezza non è definito.If the stream is expanded, the contents of the stream between the old and the new length are undefined.
Un flusso deve supportare sia la scrittura che la ricerca SetLength
di per funzionare.A stream must support both writing and seeking for SetLength
to work.
Nota
Utilizzare la CanWrite proprietà per determinare se l'istanza corrente supporta la scrittura e la CanSeek proprietà per determinare se la ricerca è supportata.Use the CanWrite property to determine whether the current instance supports writing, and the CanSeek property to determine whether seeking is supported. Per altre informazioni, vedere CanWrite e CanSeek.For additional information, see CanWrite and CanSeek.
Per un elenco delle operazioni comuni di file e directory, vedere attività di I/O comuni.For a list of common file and directory operations, see Common I/O Tasks.