本文介绍了从给定路径读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想从字符串中包含的给定路径读取字符串中的txt文件。 我正在获取路径,但文件未正确读取。 第三个声明后我收到错误:不支持给定路径的格式。 这是我在C#中的代码: string filename = basic.htm; string path = AppDomain.CurrentDomain.BaseDirectory + filename; string strArray = File.ReadAllText(path); 解决方案 Quote: string path = AppDomain.CurrentDomain.BaseDirectory + filename; 应该(可能) )be: string path = AppDomain.CurrentDomain.BaseDirectory +\\+ filename; 您的路径中可能有一个特殊字符。看看这里: http://stackoverflow.com/questions/24856821/what-is-causing-notsupportedexception-the-given-paths-format-is-not-supported [ ^ ] I want to read a txt file in string from the given path contained in string.I am getting the path but the file is not getting read properly.After third statement i am getting error: "The given path's format is not supported."Here is my Code in C#:string filename = "basic.htm";string path = AppDomain.CurrentDomain.BaseDirectory + filename;string strArray = File.ReadAllText(path); 解决方案 Quote:string path = AppDomain.CurrentDomain.BaseDirectory + filename;Should (probably) be:string path = AppDomain.CurrentDomain.BaseDirectory + "\\" + filename;There is probably a special character in your path. Have a look here:http://stackoverflow.com/questions/24856821/what-is-causing-notsupportedexception-the-given-paths-format-is-not-supported[^] 这篇关于从给定路径读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 05:39