FileStream NewFile = new FileStream(@"D:\skk\.txt ",FileMode.Create,FileAccess.Write);
我想要路径为可变的,要怎么样拼接?
我自己这样试过:
FileStream NewFile = new FileStream(@"D:\skk\" + time + ".txt ",FileMode.Create,FileAccess.Write);//其中time是一个字符串变量
但是提示有误,请问我要怎么做?
谢谢!~
我想要路径为可变的,要怎么样拼接?
我自己这样试过:
FileStream NewFile = new FileStream(@"D:\skk\" + time + ".txt ",FileMode.Create,FileAccess.Write);//其中time是一个字符串变量
但是提示有误,请问我要怎么做?
谢谢!~
str=string.Format(str,time); FileStream NewFile = new FileStream(str,FileMode.Create,FileAccess.Write);
string fileFullName=Path.Combine(@"D:\skk\", time + ".txt ");试试这个
输出看看filename是否有非法的字符,文件名不能有 /\*:"| 等字符。
string str = @"D:\skk\{0} ";
string time = @"a.txt";
str = string.Format(str, time);
if (File.Exists(str))
{
FileStream NewFile = new FileStream(str, FileMode.Create, FileAccess.Write);
}
else
Console.WriteLine("文件不存在");
看File.Exists()的注释true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.