首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C#:System.IO.DirectoryNotFoundException:‘未能找到路径的一部分

C#:System.IO.DirectoryNotFoundException:‘未能找到路径的一部分
EN

Stack Overflow用户
提问于 2018-10-07 16:53:09
回答 1查看 21.8K关注 0票数 0

我收到一个错误,如标题中所示。我不知道为什么我会得到这个,也不知道我应该如何解决这个问题。Visual Studio给出了该行标题中显示的错误: var f= System.IO.File.OpenRead(fil1);

代码语言:javascript
运行
复制
class Program {
    static void Main(string[] args) {

        Stopwatch sw = Stopwatch.StartNew();

        string fil1 = "C:\Users\mariu\Desktop\Jobboppgave\CaseConsoleApp\Prisfile.txt";

        ***var f = System.IO.File.OpenRead(fil1);***
        int length = (int)(new System.IO.FileInfo(fil1).Length);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-07 17:07:54

您的路径不正确,因为您没有在其中转义\。最快的方法是使用@

代码语言:javascript
运行
复制
string fil1 = @"C:\Users\mariu\Desktop\Jobboppgave\CaseConsoleApp\Prisfile.txt";

重新构建您的项目,问题将得到解决。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52686917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档