System.IO.FileStream.Flush C# (CSharp) Method

Flush() public method

Clears buffers for this stream, and if is true, causes any buffered data to be written to the file.
public Flush ( bool flushToDisk ) : void
flushToDisk bool
return void
        public virtual void Flush(bool flushToDisk)
        {
            if (IsClosed) throw Error.GetFileNotOpen();

            FlushInternalBuffer();

            if (flushToDisk && CanWrite)
            {
                FlushOSBuffer();
            }
        }

Same methods

FileStream::Flush ( ) : void

Usage Example

Example #1
1
        //Đưa SecretKey vào File của thuật toán 3DES
        public void AddSecretKeytoFile(string inputFile)
        {
            //Add SecretKey to File;
            if (File.Exists(inputFile))
            {
                FileStream fsOpen = new FileStream(inputFile, FileMode.Open, FileAccess.ReadWrite);
                try
                {
                    byte[] content = new byte[fsOpen.Length];
                    fsOpen.Read(content, 0, content.Length);
                    //string sContent = System.Text.Encoding.UTF8.GetString(content); //noi dung bang string

                    //byte[] plainbytesCheck = System.Text.Encoding.UTF8.GetBytes(sContent);
                    byte[] plainbytesKey = new UTF8Encoding(true).GetBytes(m_EncryptedSecretKey + "\r\n");

                    fsOpen.Seek(0, SeekOrigin.Begin);
                    fsOpen.Write(plainbytesKey, 0, plainbytesKey.Length);
                    fsOpen.Flush();
                    fsOpen.Write(content, 0, content.Length);
                    fsOpen.Flush();
                    fsOpen.Close();
                }
                catch
                {
                    fsOpen.Close();
                }
            }
        }
All Usage Examples Of System.IO.FileStream::Flush