C#读取host文件代码


本文摘自PHP中文网,作者大家讲道理,侵删。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Text;

using System.Windows.Forms;

  

  

namespace 读取host文件

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

  

  

        private void button1_Click(object sender, EventArgs e)

        {

            string str;

            StreamReader sr = new StreamReader(@"C:\windows\system32\drivers\etc" + "\\hosts", false);

            str = sr.ReadToEnd().ToString();

            sr.Close();

            this.richTextBox1.Text = str;///读取

  

        }

  

   }

  

}

  

@"C:\windows\system32\drivers\etc" + "\\hosts"文件路径

相关阅读 >>

c#实现图标锁定到windows任务栏或删除图标

c#分别用前序遍历、中序遍历和后序遍历打印二叉树

c# 四舍五入round函数使用

c#读取中文文件乱码的解方法

c#查找字符串的所有排列组合

c#测试代码执行时间的方法

c#读取host文件代码

c#访问sqlserver的工具类sqlserverhelper

c# 识别url是否是网络路径

常用的c#类

更多相关阅读请进入《代码片段》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...