Click here to Skip to main content
15,905,785 members
Home / Discussions / C#
   

C#

 
GeneralRe: Pointers Pin
Andy Brummer29-Mar-04 16:09
sitebuilderAndy Brummer29-Mar-04 16:09 
GeneralRe: Pointers Pin
Heath Stewart29-Mar-04 17:39
protectorHeath Stewart29-Mar-04 17:39 
GeneralRe: Pointers Pin
Roger H Art30-Mar-04 1:18
sussRoger H Art30-Mar-04 1:18 
GeneralRe: Pointers Pin
Heath Stewart30-Mar-04 3:37
protectorHeath Stewart30-Mar-04 3:37 
GeneralRe: Pointers Pin
Roger H Art30-Mar-04 6:22
sussRoger H Art30-Mar-04 6:22 
GeneralRe: Pointers Pin
Heath Stewart30-Mar-04 8:27
protectorHeath Stewart30-Mar-04 8:27 
GeneralNeed Help with Writing a IO.Stream Pin
David Flores29-Mar-04 8:32
David Flores29-Mar-04 8:32 
GeneralRe: Need Help with Writing a IO.Stream Pin
Heath Stewart29-Mar-04 8:40
protectorHeath Stewart29-Mar-04 8:40 
Pass the Stream into the constructor of a StreamReader, then buffer the input (in blocks, for which 4096 is a good size typically) to a TextWriter derivative (perhaps a StreamWriter with a FileStream passed to its constructor that points at the right place. This will also allow you to change the encoding if you like.

You could skip the readers and writers, though, and just buffer the input directly from the Stream to a FileStream, something like:
private void Save(Stream s)
{
  FileStream file = new FileStream("c:\temp\file.txt", ...);
  using (file)
  {
    byte[] buffer = new byte[4096];
    int read = 0;
    read = s.Read(buffer, 0, buffer.Length);
    while (read != 0)
    {
      file.Write(buffer, 0, read);
      read = s.Read(buffer, 0, buffer.Length);
    }
  }
}
A very simplistic example, but you should get the idea. The code would be similar using a TextReader and TextWriter derivative, but would allow you to more easily handle text as opposed to binary data (although you could still get an encoded string at any time using the Encoding class derivatives).

 

Microsoft MVP, Visual C#
My Articles
GeneralAccess files in use Pin
Shaun Becker29-Mar-04 7:33
Shaun Becker29-Mar-04 7:33 
GeneralRe: Access files in use Pin
Heath Stewart29-Mar-04 8:23
protectorHeath Stewart29-Mar-04 8:23 
GeneralPolymorphism and types Pin
esuyer4saic29-Mar-04 7:30
esuyer4saic29-Mar-04 7:30 
GeneralRe: Polymorphism and types Pin
Heath Stewart29-Mar-04 8:18
protectorHeath Stewart29-Mar-04 8:18 
GeneralReporting Pin
rags29-Mar-04 6:35
rags29-Mar-04 6:35 
GeneralRe: Reporting Pin
Heath Stewart29-Mar-04 8:09
protectorHeath Stewart29-Mar-04 8:09 
GeneralRe: Reporting Pin
Michael Flanakin29-Mar-04 17:25
Michael Flanakin29-Mar-04 17:25 
GeneralCustom Install Pin
dotnetdev@univ.kiev.ua29-Mar-04 6:05
dotnetdev@univ.kiev.ua29-Mar-04 6:05 
GeneralRe: Custom Install Pin
Heath Stewart29-Mar-04 8:07
protectorHeath Stewart29-Mar-04 8:07 
GeneralRe: Custom Install Pin
dotnetdev@univ.kiev.ua29-Mar-04 22:10
dotnetdev@univ.kiev.ua29-Mar-04 22:10 
GeneralRe: Custom Install Pin
Heath Stewart30-Mar-04 3:28
protectorHeath Stewart30-Mar-04 3:28 
GeneralRe: Custom Install Pin
dotnetdev@univ.kiev.ua30-Mar-04 4:18
dotnetdev@univ.kiev.ua30-Mar-04 4:18 
GeneralRe: Custom Install Pin
Heath Stewart30-Mar-04 4:24
protectorHeath Stewart30-Mar-04 4:24 
GeneralRe: Custom Install Pin
dotnetdev@univ.kiev.ua30-Mar-04 19:54
dotnetdev@univ.kiev.ua30-Mar-04 19:54 
GeneralRe: Custom Install Pin
dotnetdev@univ.kiev.ua30-Mar-04 20:42
dotnetdev@univ.kiev.ua30-Mar-04 20:42 
GeneralRe: Custom Install Pin
Heath Stewart31-Mar-04 3:14
protectorHeath Stewart31-Mar-04 3:14 
GeneralRe: Custom Install Pin
Heath Stewart31-Mar-04 3:08
protectorHeath Stewart31-Mar-04 3:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.