从文件读取 [英] reading from file

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

问题描述

如何从Web应用程序中的.txt文件或.ini文件中读取内容.我想从文本文件中的名称列表中读取每个名称.

How to read the contents from .txt file or .ini file in web application.i want to read the each name from a name list in the text file.

推荐答案

打开文件并阅读.

Open the file and read it.

using(StreamReader stream = new StreamReader("filename"))
{
    string line = null;
    while( (line = stream.ReadLine()) != null)
    {

    }
}


string fileText = System.IO.File.ReadAllText("filename")



但是ini文件是另一回事.除非您要访问旧版应用程序中的设置,否则请不要使用INI文件,而应使用web.config文件.



But ini files are a different matter. Unless you are accessing settings in a legacy app, DON''T USE INI files, instead use your web.config file.


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

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