streamwriter

Append text using StreamWriter [duplicate]

别等时光非礼了梦想. 提交于 2019-11-27 17:08:44
问题 This question already has answers here : Append lines to a file using a StreamWriter (10 answers) Closed 6 years ago . This is probably a pretty simple question. In C# I'm trying to write a simple method, called my "DebugWrite" method, to write out any exceptions caught within my program to a text file stored locally. My current code only writes a new file every time, using StreamWriter How do you program it to check if the file already exists, and if so to append to the current text?. IE: If

DataGridView to CSV File

只谈情不闲聊 提交于 2019-11-27 14:26:14
问题 I have a VB 2010 Express Project, that has a DataGridView in it, that I am trying to write to a CSV file. I have the write all working. But its slow. Slow = maybe 30 seconds for 6000 rows over 8 columns. Here is my code: Private Sub btnExportData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportData.Click Dim StrExport As String = "" For Each C As DataGridViewColumn In DataGridView1.Columns StrExport &= """" & C.HeaderText & """," Next StrExport = StrExport

How to send keys instead of characters to a process?

爱⌒轻易说出口 提交于 2019-11-27 14:11:10
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 characters. What should I do? Remus Rusanu You are mixing input streams with control signals. A console process has a default input stream which you can control with the StandardInput, as you already know. But Ctrl-C and Ctrl-Break are not characters sent to the process through this stream, but instead they are instead control signals that the process receives using the registered signal handlers, see

Forcing StreamWriter to change Encoding

一个人想着一个人 提交于 2019-11-27 12:49:20
问题 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 = new StreamWriter(saveFileDialog1.FileName); sw.Write(sb.ToString()); sw.Close(); } I tried to add the second parameter to StreamWriter as Encoding.UTF8 but since the first argument is a string rather than a Stream , it does not compile it. How can I convert that string to a stream to be able to pass the second

Create File If File Does Not Exist

别来无恙 提交于 2019-11-27 09:55:54
问题 I need to get my code to read if file doesnt exist create else append. Right now it is reading if it does exist create and append. Here is the code: if (File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { Would I do this? if (! File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { Edit: string path = txtFilePath.Text; if (!File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { foreach (var line in employeeList.Items) { sw.WriteLine((

Adding a Line to the Middle of a File with .NET

南笙酒味 提交于 2019-11-27 09:27:25
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 file more or less. Example: Hello my name is Brandon, I hope someone can help, //I want the string under this line. Thank you. Hopefully someone can help with a solution. Edit Alright thanks guys, I'll try to figure it out, probably going to just rewrite the whole file. Ok well the program I am making is related to the hosts file, and not everyone has the same hosts file, so I was wondering if

Add a new line at a specific position in a text file.

允我心安 提交于 2019-11-27 09:27:03
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] 2550 coins 995 200000 7 2550 coins 995 200000 7 2550 coins 995 200000 7 2550 coins 995 200000 7 2550 coins 995 200000 7 //Add a line here in between the specific boundaries [/item1] [item2] 2550 coins 995 200000 7 2550 coins 995 200000 7 2550 coins 995 200000 8 2550 coins 995 200000 7 2550 coins 995 200000 7 [/item2] [item3] 2550 coins 995 200000 7 2550 coins 995 200000 7 2550 coins 995 200000 7

Writing to file using StreamWriter much slower than file copy over slow network

牧云@^-^@ 提交于 2019-11-27 07:58:44
问题 I have a program that attempts to write quite a large amount of text to a file on a remote server overseas, which has a slow network connection. Using the following code, where outputFileContent is a StringBuilder : using (var outfile = new StreamWriter(myRemoteFilePath)) { outfile.Write(outputFileContent.ToString()); } it is taking a seriously long time to run (several minutes), whereas if I first write to a local file and then copy it across to the remote location, it is much quicker (20-30

Java - Writing to txt in a JAR file [duplicate]

こ雲淡風輕ζ 提交于 2019-11-27 07:50:32
问题 This question already has answers here : Closed 6 years ago . 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 errors, but it just doesn't write to the .txt inside JAR file. I make the JAR file using: netbeans clean /build tool Code: public class FileIO { private File file; private Scanner filescScanner, lineScanner; private PrintWriter fileWriter;

Exporting datagridview to csv file

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 05:02:11
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 to a source. When i try to use the Streamwriter to only write the column headers everything goes well, but when i try to export the whole datagrid including data i get an exeption trhown. System.NullReferenceException: Object reference not set to an instance of an object. at Scanmonitor.Form1.button1_Click(Object sender, EventArgs e) Here is my Code, error is given on the following line: