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

Write to File skips last 10-20 lines

First i Read all lines of a text file line by line and store it in a string-array. Then i write it with file.WriteLine() into a file. The opened Console window shows every line which was written into the file, but when i open the file to check if it…
Phil
  • 19
  • 4
-2
votes
1 answer

C# how can I write data from a two-dimensional array to a text-file and format them in columns?

So I have a two-dimensional array and I want to write all data to a text-file. But I want them to appear in columns in the text-file. (I haven't declared them like this in my code, but I think this is what the array would look like written…
Anonym
  • 9
  • 1
-2
votes
1 answer

StreamWriter randomly not outputting last line into file

I'm trying to save a class to a text file and I'm getting mixed results. Half the time the last line of the add is in the file and sometimes not. I've not been able to get a consistent output to the file. So, I added a debug to show me what was…
ErocM
  • 4,505
  • 24
  • 94
  • 161
-2
votes
2 answers

C# - How to Stop StreamWriter Writing Blank Line at the End of a File?

I have searched numerous web pages but I can't seem to find anywhere which shows how to stop a blank line appearing at the end of a file when using StreamWriter. The code I've written below is the only way I can get this to work for me.. and…
-2
votes
1 answer

Streamwriter wont overwrite file

I have easy function which creates powershell script using StreamWriter. public static void CreateDomainScript(string domain, string username, string pcname) { string path = @"C:\Windows\Temp\JoinDomain.ps1"; if…
Johny Corbie
  • 63
  • 10
-2
votes
1 answer

Streamwriter is delimiting by all commas and I need it to stop

I have a 'translate content' application. Basically, a user uses Summernote text editor to put content (HTML) into the system. They can then request a translation by downloading a csv file with all the information in it to send to the translator.…
HumanHickory
  • 464
  • 1
  • 6
  • 19
-2
votes
1 answer

Java Process console output

I need help with process outputs. I working on a Process console, and if I write to process output, I need to close to write. If I want to send another command, I get "Stream closed" error. Can anyone help me? Sources: public void runServer(String…
S3nS3IW00
  • 31
  • 6
-2
votes
1 answer

Named Pipe Input Output in C#

I am working with named pipes and very confused about how the interaction between the client and server is happening. My server is a VM with a named pipe attached to it. I have created a client stream in C# this way: NamedPipeClientStream client =…
user3552407
  • 361
  • 1
  • 4
  • 14
-2
votes
1 answer

Streamwriter missing async versions to write numbers?

A FileStream buffers the bytes it needs to write. If the buffer is full, all bytes are written (flushed) to the file. This write process might take some time. As every byte being added to the FileStream might cause a Flush, the write functions have…
Harald Coppoolse
  • 28,834
  • 7
  • 67
  • 116
-2
votes
1 answer

C# streamwriter does not overwrite futher information

i'm working on a calculator project for my school. i have a problem with overwriting my operations to a text document, normally i should have this on my text file: 1|peter|DESKTOP-P6IL7VV|19/11/2017 11:38:11 ==> 5 x 5=25 …
ach.ala
  • 7
  • 4
-2
votes
1 answer

Stream Writer File being used exception

I am making my game and i just added saving the world. This is my code: Imports Game_Functions_VB.NET.Functions.VBFuncs Imports System.IO Namespace SaveMap Public Class SaveMap Public Shared CurrentMap As Byte Public Shared Worlds(254) As…
-2
votes
2 answers

simple streamwriter not writing

So not sure why this does not work. I have this in a button on my web form. protected void btnSave_Click(object sender, EventArgs e) { using (StreamWriter sw = new StreamWriter("C:\\temp\\test.txt")) { sw.Flush(); …
maltman
  • 454
  • 1
  • 7
  • 28
-2
votes
1 answer

How to implement a SaveFileDialog in my code, where I am using a FileSteam object

so here is my code with the method, but I cannot seem to figure out how to implement a Save File Dialog within... Any information or guidance will be highly appreciated. Private Sub btSave_Click(sender As System.Object, e As System.EventArgs)…
-2
votes
1 answer

get data from a .txt file and write it on a textbox

I am trying to create a language translator I have the texts that translated the word that I need here is an example of what is inside my text file https://pastebin.com/LBv76w2f and I have two text boxes in my program, I want to get data from the…
Kaneki
  • 89
  • 1
  • 3
-2
votes
1 answer

Can't create a file in the server with Filestreams .NET

What i am trying to do is to Create or writea text file in the server to work as a data log, this code works fine in my pc, but when i build the solution and upload the server files, it creates nothing. Could it be that this code only appends the…