Questions tagged [streamwriter]
StreamWriter is designed for character output in a particular encoding, whereas classes derived from Stream are designed for byte input and output.
streamwriter
150
questions
194
votes
11
answers
461k
views
Append lines to a file using a StreamWriter
I want to append lines to my file. I am using a StreamWriter:
StreamWriter file2 = new StreamWriter(@"c:\file.txt");
file2.WriteLine(someString);
file2.Close();
The output of my file should be ...
203
votes
7
answers
191k
views
Should I call Close() or Dispose() for stream objects?
Classes such as Stream, StreamReader, StreamWriter etc implements IDisposable interface. That means, we can call Dispose() method on objects of these classes. They've also defined a public method ...
16
votes
4
answers
47k
views
simultaneous read-write a file in C#
I have a file containing data that I'd like to monitor changes to, as well as add changes of my own. Think like "Tail -f foo.txt".
Based on this thread, it looks like I should just create a ...
18
votes
8
answers
82k
views
Exporting datagridview to csv file
I'm working on a application which will export my DataGridView called scannerDataGridView to a csv file.
Found some example code to do this, but can't get it working. Btw my datagrid isn't databound ...
118
votes
7
answers
260k
views
MemoryStream - Cannot access a closed Stream
Why using (var sw = new StreamWriter(ms)) returns Cannot access a closed Stream exception while the MemoryStream is on top of this code?
using (var ms = new MemoryStream())
{
using (var sw = new ...
47
votes
4
answers
154k
views
Writing file to web server - ASP.NET
I simply want to write the contents of a TextBox control to a file in the root of the web server directory... how do I specify it?
Bear in mind, I'm testing this locally... it keeps writing the file ...
17
votes
3
answers
47k
views
Add a new line at a specific position in a text file.
I am trying to add a specific line of text in a file. Specifically between two boundaries.
An example of what it would look like if I wanted to add a line in between the boundaries of item1:
[item1]
...
14
votes
6
answers
15k
views
Adding a Line to the Middle of a File with .NET
Hello I am working on something, and I need to be able to be able to add text into a .txt file. Although I have this completed I have a small problem. I need to write the string in the middle of the ...
7
votes
4
answers
19k
views
How to send keys instead of characters to a process?
System.Diagnostics.Process exposes a StreamWriter named StandardInput, which accepts only characters as far as I know.
But I need to send keystrokes as well, and some keystrokes don't map well to ...
11
votes
5
answers
56k
views
how to use StreamWriter class properly?
I am using StreamWriter class for file operations, are there any problems in this code that I am not seeing?
Such as do I need to put it into a try catch finally block?
StreamWriter sr = new ...
10
votes
1
answer
21k
views
How to detect a Socket Disconnect in C#
I'm working on a client/server relationship that is meant to push data back and forth for an indeterminate amount of time.
The problem I'm attempting to overcome is on the client side, being that I ...
6
votes
3
answers
28k
views
Java - Writing to txt in a JAR file [duplicate]
Possible Duplicate:
How can a Java program use files inside the .jar for read and write?
How do I write to a .txt file from a JAR java compiled project?
When I run my projects, it doesn't give ...
51
votes
3
answers
154k
views
NodeJS write binary buffer into a file
I can't rewrite a file that I am getting from a binary buffer, I have checked with the original file and all bytes are the same.
This is the file create from NodeJS:
# hd test.txt | head
00000000 ...
31
votes
5
answers
104k
views
Forcing StreamWriter to change Encoding
I am trying to save a file using DialogResult and StringBuilder. After making the text, I am calling the following code to save the file:
if (dr == DialogResult.OK)
{
StreamWriter sw ...
14
votes
3
answers
13k
views
C# I/O - Difference between System.IO.File and StreamWriter/StreamReader?
Assuming I am interested only in dealing with text files, what specific advantages or disadvantages does System.IO.File methods provide when compared to StreamWriter?
Are there any performance ...