相关疑难解决方法(0)

为什么Path.Combine没有正确连接以Path.DirectorySeparatorChar开头的文件名?

从Visual Studio中的立即窗口:

> Path.Combine(@"C:\x", "y")
"C:\\x\\y"
> Path.Combine(@"C:\x", @"\y")
"\\y"
Run Code Online (Sandbox Code Playgroud)

它们似乎都应该是一样的.

旧的FileSystemObject.BuildPath()没有以这种方式工作......

.net c# file

173
推荐指数
9
解决办法
8万
查看次数

C#找不到文件

我有一个C#Visual Studio 2008表单,该表单需要读取相对文件'character / attacks.txt'的内容。即使我确定我的目录已经排序,运行它时File.Exists()也会返回false。码:

            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader("character/attacks.txt");
                int counter = 0;
                int numberOfLines = 0;
                string line;
                while ((line = file.ReadLine()) != null) { numberOfLines++; }
                string[] attacks = new string[numberOfLines];
                while ((line = file.ReadLine()) != null) { attacks[counter] = line; counter++; }
                file.Close();
                print(attacks.ToString());
            }
            catch (Exception ex) 
            {
                print("ERROR"); print("Did you edit any files?"); print(ex.ToString()); 
            }
Run Code Online (Sandbox Code Playgroud)

异常错误:

System.IO.FileNotFoundException: Could not find file 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'.
File name: 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String …
Run Code Online (Sandbox Code Playgroud)

c# file-io visual-studio-2008

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×2

.net ×1

file ×1

file-io ×1

visual-studio-2008 ×1