Answers for "how to read write text file in c#"

C#
29

c sharp how to read a text file

// To save the text as one string use 'ReadAllText()'
string text = System.IO.File.ReadAllText(@"C:\filepath\file.txt");
// To save each line seperately in an array use 'ReadAllLines()'
string[] lines = System.IO.File.ReadAllLines(@"C:\filepath\file.txt");
Posted by: Guest on February-22-2020
0

# 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)
Posted by: Guest on March-30-2022

C# Answers by Framework

Browse Popular Code Answers by Language