我正在创建一个非常基本的程序来尝试一些文件选项,在本例中,我想计算在 ReadAllText 的帮助下创建的文本文件中有多少个单词,但是,路径名始终显示异常。
\n这是我的代码:
\nvar path = @"\xe2\x80\xaa\xe2\x80\xaaC:\\Users\\pandrews\\countme.docx";\n\n //Checks if file exists or not \n if (File.Exists(path))\n {\n Console.WriteLine("File Exists");\n\n var content = File.ReadAllText(path);\n\n Console.WriteLine(content);\n\n } else {\n\n Console.WriteLine("File doesn't exist");\n\n }\n \n //Checks if directory exists, if it does it returns a list of files in the directory and shows on the console.\n\n if(Directory.Exists(@"C:\\Users\\pandrews"))\n {\n Console.WriteLine("Directory exists");\n\n var files = Directory.GetFiles(@"C:\\Users\\pandrews");\n\n foreach(var item in files)\n {\n Console.WriteLine(item);\n }\n\n } else \n {\n Console.WriteLine("Directory doesn't Exist");\n }\nRun Code Online (Sandbox Code Playgroud)\n …