c# 文件操作 判断文件是否为空的方法

2025-04-07 07:18:28
推荐回答(1个)
回答1:

protected void Page_Load(object sender, EventArgs e)
        {
            string path = string.Format(@"d:\123.txt");//需要引入using System.IO;
            if (File.Exists(path))
            {
                FileInfo fi = new FileInfo(path);
                int l = Convert.ToInt32(fi.Length);
                if (l == 0)
                {
                    Response.Write("");                   
                }
                else
                {
                    Response.Write("");                   
                }
            }
            else
            {
                File.Create(path);
                if (File.Exists(path))
                {
                    Response.Write("");                  
                }
                else
                {
                    Response.Write("");                }
            }
        }