View Subcategory

Write a string to a file

python
open('test.txt', 'wt').write('Hello World!')
clojure
(with-out-writer "output.txt" (println "Hello file!"))
csharp
System.IO.File.WriteAllText("filename.txt", "Some text to write to the file");
erlang
Line = "This line overwites file contents!\n",
{ok, IODevice} = file:open("test.txt", [write]), file:write(IODevice, Line), file:close(IODevice).
cpp
IO::StreamWriter^ stream;

try
{
stream = gcnew IO::StreamWriter("test.txt", false);
stream->WriteLine("This line overwites file contents!");
}

Append to a file

python
open('test.txt', 'at').write('Hello World!\n')
clojure
(with-out-append-writer "output.txt" (println "This is appended to the file"))
csharp
System.IO.File.AppendAllText("filename.txt", "Some text to append to the file");
erlang
Line = "This line appended to file!\n",
{ok, IODevice} = file:open("test.txt", [append]), file:write(IODevice, Line), file:close(IODevice).
cpp
IO::StreamWriter^ stream;

try
{
stream = gcnew IO::StreamWriter("test.txt", true);
stream->WriteLine("This line appended to file!");
}