如题所述
第1个回答 2017-03-10
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("<script>alert('目标文件存在,但内容为空!');</script>");
}
else
{
Response.Write("<script>alert('目标文件存在,内容不为空!');</script>");
}
}
else
{
File.Create(path);
if (File.Exists(path))
{
Response.Write("<script>alert('目标文件不存在,自动创建文件成功!');</script>");
}
else
{
Response.Write("<script>alert('目标文件不存在,自动创建文件失败!');</script>"); }
}
}
{
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("<script>alert('目标文件存在,但内容为空!');</script>");
}
else
{
Response.Write("<script>alert('目标文件存在,内容不为空!');</script>");
}
}
else
{
File.Create(path);
if (File.Exists(path))
{
Response.Write("<script>alert('目标文件不存在,自动创建文件成功!');</script>");
}
else
{
Response.Write("<script>alert('目标文件不存在,自动创建文件失败!');</script>"); }
}
}