小编Mar*_*usD的帖子

C#的新手 - 无法让File.Copy工作

这是Microsoft的代码示例,具有不同的文件位置,但不起作用:

 string fileName = "test1.txt";
 string sourcePath = @"C:\";
 string targetPath = @"C:\Test\";

 // Use Path class to manipulate file and directory paths.
 string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
 string destFile = System.IO.Path.Combine(targetPath, fileName);

 System.IO.File.Copy(sourceFile, destFile, true);
Run Code Online (Sandbox Code Playgroud)

它找不到源文件.如果我设置了一个断点,这就是我得到的:

    args    {string[0]} string[]
    fileName    "test1.txt" string
    sourcePath  "C:\\"  string
    targetPath  "C:\\Test\\"    string
    sourceFile  "C:\\test1.txt" string
    destFile    "C:\\Test\\test1.txt"   string
Run Code Online (Sandbox Code Playgroud)

因此,即使使用逐字字符串,它看起来也会加倍反斜杠.(毫无疑问,我在C中有一个test1.txt文件:)有什么想法吗?谢谢!

c# string verbatim

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

标签 统计

c# ×1

string ×1

verbatim ×1