using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO;namespace WindowsApplication1 { static class Program { static void Main() { string pathfile = ""; if (File.Exists(pathfile)) { Console.Write("存在该文件!"); } else { Console.Write("不存在该文件!"); } } } }
{
FileStream fs = new FileStream(pathfile,FileMode.Open,FileAccess.ReadWrite);
}
catch(Exception ex)
{
MessageBox.Show("该文件不存在");
}
using System.IO;
namespace Hello
{
public class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine("验证文件是否存在");
string strPath = Console.ReadLine();
try
{
if (File.Exists(strPath))
{
Console.WriteLine("存在");
}
else
{
Console.WriteLine("不存在");
}
}
catch
{
Console.WriteLine("估计是你乱填写地址,看看把错误搞出来了吧!!");
}
Console.ReadKey();
}
}
}//最好自己写一个bool类型的方法,如果存在返回true!
{
//存在
}
else
{
//不存在
}
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;namespace WindowsApplication1
{
static class Program
{
static void Main()
{
string pathfile = "";
if (File.Exists(pathfile))
{
Console.Write("存在该文件!");
}
else {
Console.Write("不存在该文件!");
}
}
}
}