//File and path you want to create and write to
string fileName = @"C:TempTemp.txt";
//Check if the file exists
if (!File.Exists(fileName))
{
// Create the file and use streamWriter to write text to it.
//If the file existence is not check, this will overwrite said file.
//Use the using block so the file can close and vairable disposed correctly
using (StreamWriter writer = File.CreateText(fileName))
{
writer.WriteLine("Hello World");
}
}
// Create a file to write to.
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText);
...
// Open the file to read from.
string readText = File.ReadAllText(path);
# read Text from File
def read_file(filename):
with open(filename, encoding='utf-8') as file:
return file.readlines()
# write Text to File
def write_to_file(filename, text):
with open(filename, 'w', encoding='utf-8') as file:
file.write(text)