3.1 System.IO命名空间
3.1.1 System.IO类介绍
![2789632-2f4aebdd4be82944.png](https://i-blog.csdnimg.cn/blog_migrate/22db9e524f9530e0af10e5c936d1731f.webp?x-image-process=image/format,png)
![2789632-2d68151c8c0e6fc4.png](https://i-blog.csdnimg.cn/blog_migrate/e81e6ab8c176ff91fb321c51d45db618.webp?x-image-process=image/format,png)
![2789632-8d577c19d5e84c62.png](https://i-blog.csdnimg.cn/blog_migrate/89cc5a989ce3d54689653964d0149b31.webp?x-image-process=image/format,png)
3.1.2 File类的常用方法
File类提供用于创建、复制、删除、移动和打开文件的静态方法,并协助创建FileStream对象。
![2789632-5d635f096736b0df.png](https://i-blog.csdnimg.cn/blog_migrate/b6b37382cdaf91f004e8f722a568682f.webp?x-image-process=image/format,png)
小练习:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileTest
{
class Program
{
static void Main(string[] args)
{
string path = @"D:\\Test.txt";
if (!File.Exists(path))
{
//创建文件,以便写入内容
using (StreamWriter sw = File.CreateText(path))
{
List<string> ls_string = new List<string> {"a","b","c","d","e","f","g","h","i","j","k","l" };
foreach (var tes in ls_string)
{
sw.Write(tes);
}
foreach (var tes in ls_string)
{
sw.WriteAsync(tes);
}
}