使用文件系统在localhost中读取.txt文件 [英] reading a .txt file in localhost by using file system

查看:91
本文介绍了使用文件系统在localhost中读取.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这是lakshmana rao.i代码错误

hi to all, This is lakshmana rao.i have an error in code

using System.IO;
    FileStream fs;
    StreamWriter sw;
    StreamReader sr;



fs = new FileStream("http://localhost/jtm_site/Documents/About Me.txt", FileMode.Open, FileAccess.Read);
        sr = new StreamReader(fs);
        if (sr.Peek() > 0)
        {
            Label3.Text = sr.ReadToEnd();
        }
        fs.Flush();
        fs.Close();





错误为不支持URI格式."
如果我这样写





The Error is "URI formats are not supported."
If i write like this

fs = new FileStream("C:\\Users\\LUCKY\\Documents\\Visual Studio 2008\\WebSites\\WebSite7\\" + s + ".txt", FileMode.Open, FileAccess.Read);

,它将为我工作,但是我希望从本地主机地址访问它.谁能建议我.

it will work for me, but i want it from localhost address. can any one suggest me.

推荐答案

u可以为此使用server.mappath

查看此链接

http://stackoverflow.com/questions/275781/server-mappath- server-mappath-server-mappath-server-mappath [ ^ ]

http://msdn.microsoft.com/en-us/library/ms524632 (v = vs.90).aspx [
u can use server.mappath for this

see this links

http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath[^]

http://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx[^]


您可以尝试使用虚拟路径并使用其调用MapPath

You could try using a virtual path and call MapPath with it

fs = new FileStream(MapPath("~/Documents/About Me.txt"), FileMode.Open, FileAccess.Read);


这篇关于使用文件系统在localhost中读取.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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