Questions tagged [filestream]

In .NET framework filestream exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations. ActionScript 3 for AIR 2 and above also uses FileStream, which supports both synchronous and asynchronous read and write operations.

2638 questions
202
votes
6 answers

How to append text to a text file in C++?

How to append text to a text file in C++? And create a new text file if it does not already exist and append text to it if it does exist.
Ahmad Farid
  • 13,132
  • 45
  • 92
  • 134
87
votes
6 answers

FileStream vs/differences StreamWriter?

Question: What is different between FileStream and StreamWriter in .Net? What context are you supposed to use it? What is their advantage and disadvantage? Is it possible to combine these two into one?
What'sUP
  • 12,102
  • 23
  • 71
  • 120
73
votes
6 answers

How to both read and write a file in C#

I want to both read from and write to a file. This doesn't work. static void Main(string[] args) { StreamReader sr = new StreamReader(@"C:\words.txt"); StreamWriter sw = new StreamWriter(@"C:\words.txt"); } How can I both read from and…
Hey
72
votes
3 answers

C# FileStream : Optimal buffer size for writing large files?

Suppose I'm writing a couple of files to disk, between 2MB and 5GB. What are sensible buffer values for the FileStream ? Is it sensible to work with buffersizes of several megabytes, or should I stick to kilobyte-buffers ?
Pygmy
  • 1,656
  • 2
  • 17
  • 12
66
votes
8 answers

difference between memory stream and filestream

During the serialization we can use either memory stream or file stream. What is the basic difference between these two? What does memory stream mean? using System; using System.Collections.Generic; using System.Linq; using System.Text; using…
Raghav55
  • 2,725
  • 6
  • 24
  • 36
65
votes
2 answers

FileStream and creating folders

Just a quick question. I'm using something like this FileStream fs = new FileStream(fileName, FileMode.Create); I was wondering whether there was a parameter I could pass to it to force it to create the folder if it doesn't exist. At the moment an…
Ash Burlaczenko
  • 21,581
  • 14
  • 63
  • 95
55
votes
7 answers

Access to the path denied error in C#

I have read a similar post, but i just cant figure out the problem. I have changed the windows permissions and changed routes. When i try to save a file it throws me the exception: Access to the path **** denied. string route="D:\\"; FileStream…
aerojun
  • 1,066
  • 2
  • 14
  • 27
53
votes
5 answers

Returning a stream from File.OpenRead()

I'm in the process of writing a WCF service that will allow an ASP.Net web site to retrieve files (based on this article). My problem is that when I return the stream, it's blank. For simplicity, I've isolated the code into a simple winforms app to…
GrandMasterFlush
  • 5,857
  • 17
  • 73
  • 98
53
votes
4 answers

What is a stream in C++?

I have been hearing about streams, more specifically file streams. So what are they? Is it something that has a location in the memory? Is it something that contains data? Is it just a connection between a file and an object?
Mohamed Ahmed Nabil
  • 3,389
  • 8
  • 32
  • 48
47
votes
3 answers

Getting Original Path from FileStream

Given a System.IO.FileStream object, how can I get the original path to the file it's providing access to? For example, in the MyStreamHandler() function below, I want to get back the path of the file that created the FileStream: public static void…
user116592
46
votes
5 answers

Byte Stream and Character stream

Please explain what Byte streams and Character streams are. What exactly do these mean? Is a Microsoft Word document Byte oriented or Character oriented? Thanks
JavaUser
  • 22,494
  • 44
  • 98
  • 127
44
votes
3 answers

Copy MemoryStream to FileStream and save the file?

I don't understand what I'm doing wrong here. I generate couple of memory streams and in debug-mode I see that they are populated. But when I try to copy MemoryStream to FileStream in order to save the file fileStream is not populated and file is…
Stan
  • 22,856
  • 45
  • 148
  • 231
41
votes
2 answers

Easiest way to read text file which is locked by another application

I've been using File.ReadAllText() to open a CSV file, but every time I forget to close the file in Excel, the application throws an exception because it can't get access to the file. (Seems crazy to me, I mean the READ in ReadAllText seems pretty…
Benjol
  • 57,639
  • 51
  • 180
  • 252
40
votes
5 answers

Edit a specific Line of a Text File in C#

I have two text files, Source.txt and Target.txt. The source will never be modified and contain N lines of text. So, I want to delete a specific line of text in Target.txt, and replace by an specific line of text from Source.txt, I know what number…
Luis
  • 403
  • 1
  • 4
  • 4
38
votes
6 answers

Encode a FileStream to base64 with c#

I know how to encode / decode a simple string to / from base64. But how would I do that if the data is already been written to a FileStream object. Let's say I have only access to the FileStream object not to the previously stored original data in…
feedwall
  • 1,213
  • 6
  • 25
  • 48
1
2 3
99 100