1.利用File.CreateText()来创建文本文件。

代码如下:

IO 使用File创建文本 streamwrite 写入字符,streamread输出字符

 

代码如下:

  static void Main(string[] args)
        {
            
string path = @"c:\temp\MyTest.txt";
            
if (!File.Exists(path))
            { 
                
try
                {
                    
using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.WriteLine(
"this is my name");
                        sw.WriteLine(
"what about you");
                        sw.Write(
"?I fine");
                    }
                }
                
catch (DirectoryNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.ReadLine();
            }

        }

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-11-14
  • 2021-04-14
  • 2021-12-09
  • 2021-11-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案