C# StreamWriter Write(Char[], Int32, Int32)

Description

StreamWriter Write(Char[], Int32, Int32) Writes a subarray of characters to the stream.

Syntax

StreamWriter.Write(Char[], Int32, Int32) has the following syntax.


public override void Write(
  char[] buffer,/*from  w w  w.j a  va 2 s.  c  om*/
  int index,
  int count
)

Parameters

StreamWriter.Write(Char[], Int32, Int32) has the following parameters.

  • buffer - A character array that contains the data to write.
  • index - The character position in the buffer at which to start reading data.
  • count - The maximum number of characters to write.

Returns

StreamWriter.Write(Char[], Int32, Int32) method returns

Example

This example writes eight characters from a 13-element array to a file, beginning at the third element of the array.


//from ww  w .j a  va2 s. c om
using System;
using System.IO;

public class SWBuff 
{
    public static void Main(String[] args)
    {
        FileStream sb = new FileStream("MyFile.txt", FileMode.OpenOrCreate);
        char[] b = {'a','b','c','d','e','f','g','h','i','j','k','l','m'};
        StreamWriter sw = new StreamWriter(sb);
        sw.Write(b, 3, 8);
        sw.Close();
    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter