Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# create a text file

//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");
    }	
}
Comment

write text files with C#

// 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);
Comment

# read and write a text file

# 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)
Comment

PREVIOUS NEXT
Code Example
Csharp :: get folders in directory c# 
Csharp :: c# shuffle list 
Csharp :: dropdown wpf 
Csharp :: how to find a gameobject in unity 
Csharp :: random in unity 
Csharp :: get time from datetime c# 
Csharp :: unity create gameobject 
Csharp :: know to which direction Vector.MoveTowards is moving unity 2D 
Csharp :: button size xamarin 
Csharp :: c# write variable in string 
Csharp :: unity c# 
Csharp :: c# substring from end 
Csharp :: List string to file C# 
Csharp :: linux command line switch statement 
Csharp :: c# get pressed key 
Csharp :: how to set the frame rate unity 
Csharp :: c# convert split to list 
Csharp :: c# get command line arguments 
Csharp :: unity debug c# code with console 
Csharp :: newtonsoft create dynamic object 
Csharp :: c# read file from directory 
Csharp :: httpclient post c# example 
Csharp :: The server requested authentication method unknown to the client 
Csharp :: last two characters of string c# 
Csharp :: add text to combobox c# 
Csharp :: 2d rotation unity 
Csharp :: hide button unity 
Csharp :: color unity 
Csharp :: asp.net core get previouse url 
Csharp :: raylib c# 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =