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
-1
votes
1 answer

Console CLI application to Draw Ascii Art to a File (SetConsoleCursorPosition)

I'd like to write to a text file such that whenever a user hits a key, the file gets updated with an Ascii character somewhere specific in the file (not appended at the end), and not shown on the screen. While the following code worked when…
ben
  • 473
  • 2
  • 9
  • 21
-1
votes
1 answer

Write output to a csv file from list of objects C# in Winforms

I took the input from the csv file, processed and stored the results in the List of Objects of the 'OutputRecords' class. I used Lumenworks CsvReader for this task. Please help me out so as to how to create a new csv File and write the output to…
Madhur
  • 1
  • 1
-1
votes
2 answers

How to convert the steamwriter code in C# to python

I have written c# code and i need this to be written in python but i dont no how to use stream writer in python.Please help me how to use the stream writer functionality in python TextWriter tw = new StreamWriter(val); …
vinod raj
  • 69
  • 2
  • 10
-1
votes
1 answer

Getting "Cannot write to a closed TextWriter." when using StreamWriter, not sure why?

Im using StreamWriter in a loop and on the first write attempt I am getting the "Cannot write to a closed TextWriter" error but the resource has just been opened so im not sure why this is, here is the code:- if(File.Exists(filename) == false) …
GKonheiser
  • 61
  • 1
  • 10
-1
votes
1 answer

StreamWriter throws NotSupportedException

I simply want to write data from a listBox to a textfile. The name of the textfile should include the current date and time. string filename = String.Concat(string.Format("{0:yyyy-MM-dd}", DateTime.Today), "_", string.Format("{0:HH:mm:ss}",…
Boozzz
  • 245
  • 1
  • 6
  • 19
-1
votes
2 answers

Stream not readable

I'm sorry for not knowing a better way to subject this issue. I can modify once I better understand what is happening. I am trying to use a StreamWriter in the following code block: public static bool SendFileToPrinter(string szPrinterName, string…
Gernatch
  • 175
  • 3
  • 19
-1
votes
1 answer

Looping to initialize multiple StreamWriters

I want to do something like the following: int loopCount = 0; while (loopCount != 18) { StreamWriter DBSplit + loopCount = new StreamWriter(@"L:\BananaDB\DBFILE" + loopCount + ".txt"); loopCount++; } What is the best way to do this? At…
Mitchell
  • 169
  • 1
  • 14
-1
votes
1 answer

C# WriteLine inside loop generating random numbers only writing on result 100x

I am writing an application in C# for a class project and having troubles writing out the results. It is supposed to simulate rolling a pair of dice 100 times and writing out the results to a sequential file. When I run the code, the loop writes…
-1
votes
1 answer

VB.NET reading and writing to file at the same time

I want to remove data that is in the middle of the file, because the file is large, I would like to avoid having to re-write the entire file. To move the data i am trying to: Read from end of data(byte position) to end of file --> to the beginning…
Daniel Valland
  • 1,057
  • 4
  • 21
  • 45
-1
votes
1 answer

C# .NET - Garbled character when writing 56623 with StreamWriter

I have an issue with writing the character 56623 to a stream using a StreamWriter in UTF16 (the issue persists in other encodings as well). If I get the buffer from the stream, it contains the value 65533 instead of what I originally wrote. This…
Robert Kaufmann
  • 768
  • 1
  • 9
  • 21
-1
votes
1 answer

Displaying Top 3 Customers and Amounts in ListBox From TextFile

I'm looking to display the top three customers and their total amounts from a textfile in the listbox/listview when the form is loaded, I was wondering if this is possible using arrays? There are multiple figures in the textfile including other…
user2884461
  • 109
  • 1
  • 2
  • 9
-1
votes
1 answer

Putting certain lines of a textfile into an editable listbox

So I want to put certain lines into a text box, say I use the "Search Function" to search transaction ID, it would look through the transactions.txt file and find the transaction ID and Read the 6 lines under it which show the transactions Details,…
user2884461
  • 109
  • 1
  • 2
  • 9
-1
votes
1 answer

C# print multiple columns in different cells in EXCEL

I am working on C# in Win 7. I need to print to a .txt file by Streamwriter. StreamWriter outputfile = new StreamWriter(MYPATH, true); outputfile.Write(String.Format(WIDTH_1 + Constants.WIDTH_1, item1 + " " + subitem + "(ave.)" ,…
user2420472
  • 1,127
  • 1
  • 12
  • 20
-1
votes
1 answer

StreamWriter leaving a file even if not saved

I have this code to write some data from textboxes into a textfile. And i'm using streamwriter to do this. Here you may see the code below: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click …
Jeff
  • 17
  • 1
  • 6
-1
votes
1 answer

windows forms array to file

Newbie here, currently studying C# course and totally new to coding and stuff. Sorry if this question is already been asked, I've been googling for quite some time and still unable to find a proper answer or anything near it. Question being simple.…