从给定路径读取文件 [英] Reading a file from given path

查看:55
本文介绍了从给定路径读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从字符串中包含的给定路径读取字符串中的txt文件。

我正在获取路径,但文件未正确读取。



第三个声明后我收到错误:不支持给定路径的格式。



这是我在C#中的代码:



  string  filename =   basic.htm; 
string path = AppDomain.CurrentDomain.BaseDirectory + filename;
string strArray = File.ReadAllText(path);

解决方案

< blockquote>

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 [< a href =http://stackoverflow.com/questions/24856821/what-is-causing-notsupportedexception-the-given-paths-format-is-not-supportedtarget =_ blanktitle =New Window> ^ ]

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[^]


这篇关于从给定路径读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆