[问题描述:]通过程序,读取一文本文件(test.ini,格式见下文),并以txt文本格式显示,不要html格式;
[文件格式:]file name: test.ini
sameple1 lily    update new code file
sameple1 lily    update new code file
sameple1 lily    update new code file
sameple1 lily    update new code file
sameple1 lily    update new code filesameple1 lily    update new code file
sameple1 lily    update new code file
sameple1 lily    update new code file
[详细要求:]通过程序,读取此文本文档,就如同用"记事本"打开,一样的效果,不能是html格式;
[编译环境:]vs.net 2003 + windows xp sp2

解决方案 »

  1.   

    using System;
    using System.IO;class FileTest
    {
    static void Main(string [] args)
    {
    string filename="testfile.txt";
    //打开文件并显示其内容
    StreamReader reader=null;
    try
    {
    reader=new StreamReader(filename);
    for(string line=reader.ReadLine();line!=null;line=reader.ReadLine())
    Console.WriteLine(line);
    }
    catch(IOException e)
    {
    Console.WriteLine(e.Message);
    }
    finally
    {
    if(reader!=null)
    reader.Close();
    }
    }
    }
      

  2.   

    FileInfo fi = new FileInfo (_filepath);
    FileStream fs;
    //将文件读取到文件流中
    fs = fi.OpenRead ();
    //声明一读取文件流类的实例,用以读取文件流
    StreamReader sr = new StreamReader (fs);
    string myreader = sr.ReadLine() ;//文件数据
    while(myreader != null)
    {
        //把读取的内容一行一行的写到RichTextBox里面
        myreader = sr.ReadLine();
    }用以上的方法读,然后把读取的内容一行一行的写到RichTextBox里面.
      

  3.   

    或直接用Process打开.
    ProcessStartInfo startInfo = new ProcessStartInfo() ;
    startInfo.UseShellExecute = true;
    startInfo.Verb = "Open";
    startInfo.CreateNoWindow = false;
    startInfo.WindowStyle = ProcessWindowStyle.Maxmized;
    startInfo.FileName = filename;//文本文件名
    processInstance.StartInfo =startInfo;
    processInstance.Start();
      

  4.   

    using System.Diagnostics;
     // 先添加引用,再用下面的语句即可,文件的路径D:\\test.ini自己改在vs2005下测试通过System.Diagnostics.Process.Start(System.Environment.SystemDirectory + "\\notepad.exe", "D:\\test.ini");
      

  5.   

    FileInfo fi = new FileInfo (_filepath);
    FileStream fs;
    //将文件读取到文件流中
    fs = fi.OpenRead ();
    //声明一读取文件流类的实例,用以读取文件流
    StreamReader sr = new StreamReader (fs);
    string myreader = sr.ReadLine() ;//文件数据
    while(myreader != null)
    {
        //把读取的内容一行一行的写到RichTextBox里面
        myreader = sr.ReadLine();
    }用以上的方法读,然后把读取的内容一行一行的写到RichTextBox里面.
      

  6.   

    楼上几位方法基本都可以实现,最简单的方法,由于是文本文件,可以直接用streamReader用StreamReader.ReadLine()方法即可实现大致如下:
    StreamReader sd=new StreamReader("youfile");
    string line=sd.ReadLine();
    while(line!=null)
    {
         //输出,比如用console
         Console.writeLine(line);
         line=sd.ReadLine();
    }很简单,楼主都可一试.....
      

  7.   

    [详细要求:]通过程序,读取此文本文档,就如同用"记事本"打开,一样的效果,不能是html格式
    现在读取是解决了,谢谢各位的帮助,等我做完,现在在解决,浏览此文件时,如同"记事本",一样效果,还没解决!
      

  8.   

    这个也是最复杂的
    在csdn里可以下载到一个用c#写的记事本的例子,楼主不妨看看.
    http://down.csdn.net/html/2006-02/23/139484.html
      

  9.   

    System.Diagnostics.Process.Start(System.Environment.SystemDirectory + "\notepad.exe", "F:\showimage.html")
    //可以用
      

  10.   

    //C#如下
    System.Diagnostics.Process.Start(System.Environment.SystemDirectory + "\\notepad.exe", "F:\\showimage.html")
    //可以用
      

  11.   

    应该测下那个速度最快,估计是streamreader
      

  12.   

    to dlzhangln(才高七八斗,学富五六车,改行三四次,月入一两千!) :
    你的方法,我试了,没有成功!
      

  13.   

    我有专门INI文件类using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;namespace eMonitor
    {
    /// <summary>
    /// IniFile 的摘要说明。
    /// </summary> public class IniFile

    public string inipath; 
    [DllImport("kernel32")] 
    private static extern long WritePrivateProfileString(string section,string key,string val,string filePath); 
    [DllImport("kernel32")] 
    private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath); 
    /// <summary> 
    /// 构造方法 
    /// </summary> 
    /// <param name="INIPath">文件路径</param> 
    public IniFile(string INIPath) 

    inipath = INIPath; 

    /// <summary> 
    /// 写入INI文件 
    /// </summary> 
    /// <param name="Section">项目名称(如 [TypeName] )</param> 
    /// <param name="Key">键</param> 
    /// <param name="Value">值</param> 
    public void IniWriteValue(string Section,string Key,string Value) 

    WritePrivateProfileString(Section,Key,Value,this.inipath); 

    /// <summary> 
    /// 读出INI文件 
    /// </summary> 
    /// <param name="Section">项目名称(如 [TypeName] )</param> 
    /// <param name="Key">键</param> 
    public string IniReadValue(string Section,string Key) 

    StringBuilder temp = new StringBuilder(500); 
    int i = GetPrivateProfileString(Section,Key,"",temp,500,this.inipath); 
    return temp.ToString(); 

    /// <summary> 
    /// 验证文件是否存在 
    /// </summary> 
    /// <returns>布尔值</returns> 
    public bool ExistINIFile() 

    return File.Exists(inipath); 

    }
    }
      

  14.   

    To:lz
    没有成功,是什么效果
      

  15.   

    to dlzhangln(才高七八斗,学富五六车,改行三四次,月入一两千!) :
    空白页面
      

  16.   

    richTextBox1.LoadFile(filename,RichTextBoxStreamType.PlainText);
      

  17.   

    把 \n 给Replace成 <br>  然后全部Response.Write出来.
      

  18.   

    相似问题
    http://community.csdn.net/Expert/topic/4680/4680126.xml?temp=.8946802
      

  19.   

    问题解决,结帖,
    解决办法如下:[问题描述:]通过程序,读取一文本文件(test.ini,格式见下文),并以txt文本格式显示,不要html格式;
    [文件格式:]file name: test.ini
    sameple1 lily    update new code file
    sameple1 lily    update new code file
    sameple1 lily    update new code file
    sameple1 lily    update new code file
    sameple1 lily    update new code filesameple1 lily    update new code file
    sameple1 lily    update new code file
    sameple1 lily    update new code file
    [详细要求:]通过程序,读取此文本文档,就如同用"记事本"打开,一样的效果,不能是html格式;
    [编译环境:]vs.net 2003 + windows xp sp2
    [解决方法:]
    解决读取文件问题:
    using System.IO;string line_string ;
    StreamReader Filesrd=new StreamReader(filePath);//filePath  :文件的绝对路径
    string line_string = Filesrd.ReadLine();
    while(line_string!=null)
    {
        this.Response.Write(line_string+"<br>");
        line_string = Filesrd.ReadLine();
    }
    解决如同"记事本"一样,浏览,不要html格式:
    思路:把文件流里的内容,读取并存储到一个指定文件里(ls_file_path)
    StreamReader myreader = new StreamReader(file_path);//filePath  :文件的绝对路径          
    FileInfo MyFileInfo = new FileInfo(ls_file_path);//ls_file_path,格式为:c:\test\chk.ini,绝对路径
    using (FileStream fs = MyFileInfo.Create())
    {
      Byte[] info = new UTF8Encoding(true).GetBytes(myreader.ReadToEnd());
      fs.Write(info, 0, info.Length);
    }Response.Redirect("")//---------注意,这里要传一参数,表明文件被存储的位置,用相对路径
    [简单回顾:]在打开文件浏览,这一部分,我个人并不满意,只是一个折中方案;更多信息,有待再续;
    Trackback:
    http://community.csdn.net/Expert/topic/5121/5121794.xml?temp=.7716486