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.

In .Net StreamWriter (under System.IO) is designed for character output in a particular encoding, whereas classes derived from Stream are designed for byte input and output.

StreamWriter defaults to using an instance of UTF8Encoding unless specified otherwise. This instance of UTF8Encoding is constructed without a byte order mark (BOM), so its GetPreamble method returns an empty byte array. The default UTF-8 encoding for this constructor throws an exception on invalid bytes. This behavior is different from the behavior provided by the encoding object in the Encoding.UTF8 property. To specify a BOM and determine whether an exception is thrown on invalid bytes, use a constructor that accepts an encoding object as a parameter, such as StreamWriter(String, Boolean, Encoding) or StreamWriter.

By default, a StreamWriter is not thread safe
See official documentation from Microsoft.

1524 questions
-2
votes
1 answer

Three nested Object to file *.txt in C++

i want write an Object to file (*.txt) class MyCircle{ double x; double y; double radius; char index; int check;} class Question{ int index; int quantityOfAnswers; MyCircle [] arrCircles; …
Jetly_93
  • 11
  • 5
-2
votes
2 answers

How to delay the StreamWriter loop?

I'm trying to use this newbie-handy console "outputer". When I try to apply the loop on it, it either goes nuts producing huge amounts of lines in output file or not working at all if try to use delay. Extremely simplified version of my…
Rooger
  • 11
  • 5
-2
votes
1 answer

StreamWriter cannot write into a file although it is closed

I have the following problem: I use this code to open a file and write to it: using (FileStream fileStream = new FileStream(saveDir + @"\" + saveFile, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite)) { StreamWriter streamWriter = new…
HT085
  • 11
  • 4
-2
votes
2 answers

python write 40 times loops results in text

I wanna loop the following scripts for 40 times ,then write it into a txt file.However, I am the begginning user of Python, no idea how to do that, print ('TIME = 0.00 hours since 1999-06-30 14:00:00 +00:00') print ('x_spw_eye …
-2
votes
2 answers

Replacing a certain word in a text file

I know this has been asked a few times, but I have seen a lot of regex etc., and I'm sure there is another way to do this with just a stream reader/writer. Below is my code. I'm trying to replace "tea" with the word "cabbage". Can somebody help? I…
Harvey993
  • 41
  • 1
  • 1
  • 4
-2
votes
3 answers

If no text to write via StreamWriter, then discard (do not create) the file

I am using the StreamWriter to create a file and to write some text to that file. In some cases I have no text to write via StreamWriter, but the file was already created when StreamWriter was initialized. using (StreamWriter sw = new…
jadrijan
  • 1,438
  • 4
  • 31
  • 48
-2
votes
4 answers

C# StreamWriter across methods

How to use a same StreamWriter across various methods in a class. For eg. public class XMLWriter { public export(string filename) { StreamWriter sw = new StreamWriter(filename) sw.write("Line1") } public…
WoodyStory
  • 471
  • 1
  • 4
  • 9
-2
votes
3 answers

Streamwriter Not Working

I'm trying to write a variable in a txt file, but it's not really working. If I replace the variable with just a normal string it's fine. Code: Private Sub write() Dim writer As System.IO.StreamWriter writer =…
Dave12311
  • 29
  • 5
-2
votes
1 answer

How can I feed commands to cmd.exe process via an input stream manually?

The question sounds a bit, dense. Here is a slightly longer version: I need to have the main loop wait for user input and also have a process running and waiting for input from a stream to which the user input is to be sent. Full story: I'm building…
TaW
  • 53,122
  • 8
  • 69
  • 111
-2
votes
3 answers

Taking user input from a textbox to create a text file name

I am using Visual Studio 2013 and C# I currently have a form which, among other items, has a textbox for the user to enter an id number. I want to be able to 'take' this number and create a text file with the ID number as a file name. I have been…
smokeAndMirrors
  • 155
  • 1
  • 5
  • 18
-2
votes
2 answers

Split a text file into multiple files based on a condition by reading line by line in C#

I have a text file having some information in the form a table, having some imporatant data at a specific column. I need to read the text file and split the files into several files based on the value in the column. Example: ID Course Name …
Harsha V Chunduri
  • 394
  • 1
  • 4
  • 17
-2
votes
1 answer

how to use a streamreader with button.Image

Edit: the map[][] is filled with buttons The main issue is that an .image seems not to be able to save . i want to make a load that when i load it in every map[i][j] regains its previous state. everything seems to work exept for the…
Kapein
  • 175
  • 13
-2
votes
2 answers

System IO Exception was unhandled

I'm trying to develop my first application in C#, and I'm simply trying to read and write from a file. I've done hours of research, had mentors attempt to teach me, but its just not making sense to me. I've got the beginning of my Form laid out,…
Jake Tully
  • 13
  • 2
-2
votes
1 answer

Using StreamWriter and FileSystemWatcher Together

I have a program that is monitoring a directory for changes using the FileSystemWatcher class. I have some other clients writing to this directory using a StreamWriter. "Sometimes", in the filesystemwatcher created event, when I try to access the…
swiftgp
  • 997
  • 1
  • 9
  • 17
-3
votes
1 answer

Streamwriter and special character to the textfile/csv file

Need assistant :) Trying to create a csv/txt file I need some of the text to have " before and after the text How can i do that, i have tried several things with no luck This is my code using (StreamWriter writer = new…
Ace2874
  • 25
  • 7
1 2 3
99
100