There are various ways to add text to files, although I was wondering if anyone knows the shortest way to do this.
eg. Add a new line to the existing txt file:
line1 line2 <new-line-here>
It will be something like:
File.AppendAllText("c:\filepath.txt", "text to append");
See File.AppendAllText for details . The File class contains many useful static methods for performing common file operations.
The static methods of the File class do this fairly straightforward:
File.AppendAllLines("filename.txt", new string[] { "text to append" });
Edit: Using an array is a little shorter.
System.IO.File.AppendAllText("some file", Environment.NewLine);
Is that what you mean?
Try this code
StreamWriter sw = File.AppendText(file_path); sw.WriteLine("appended text");
Source = http://msdn.microsoft.com/en-us/library/system.io.file.appendtext.aspx
System.IO.File.AppendAllText(@"c:\test.txt",Environment.NewLine);
The right way to do this, just \ n don't do this!
Source: https://habr.com/ru/post/903983/More articles:Applying CGAffineTransform to CGPath - iosUnrecognized selector sent to UIBarButtonItem setTintColor - iosDisplay of CGContext and Retina - iphoneWhy aren't all my files cached using op apc code? - phpWriting SSL Checker using Java - javaHow to use pkginclude_HEADERS and Automake to get a second include directory? - automakeGL_DRAW / READ_FRAMEBUFFER vs GL_FRAMEBUFFER? - c ++Hide block (and remember it) with JavaScript and cookies? - javascriptRefuse partial view on server or send json data and render template on client - javascriptHow to detect 45 degree faces in an image - image-processingAll Articles