记事本中的数据如下:
123 x123456 123456
kkk xxxddfd dfelfe
最好能解释的详细点,我是新手。在线等
c# 如何读取记事本中的数据
答案:6 悬赏:10 手机版
解决时间 2021-03-29 13:47
- 提问者网友:临风不自傲
- 2021-03-28 13:28
最佳答案
- 五星知识达人网友:慢性怪人
- 2021-02-23 22:43
using System.IO;
//写入
StreamWriter sw = new StreamWriter( @"C:\temp123.txt");
sw.WriteLine("----------------hello----------------");
sw.WriteLine("内容");
sw.WriteLine("----------------hello----------------");
sw.Flush();
sw.Close();
//读取
System.IO.StreamReader st;
st = new System.IO.StreamReader(@"C:\temp123.txt", System.Text.Encoding.UTF8);//UTF8为编码
this.textBox1.Text = st.ReadToEnd();
StreamWriter sw = new StreamWriter( @"C:\temp123.txt",true);
后边参数为true就是 有新数据继续写
要是为false 就是 后边的数据覆盖前边的
//写入
StreamWriter sw = new StreamWriter( @"C:\temp123.txt");
sw.WriteLine("----------------hello----------------");
sw.WriteLine("内容");
sw.WriteLine("----------------hello----------------");
sw.Flush();
sw.Close();
//读取
System.IO.StreamReader st;
st = new System.IO.StreamReader(@"C:\temp123.txt", System.Text.Encoding.UTF8);//UTF8为编码
this.textBox1.Text = st.ReadToEnd();
StreamWriter sw = new StreamWriter( @"C:\temp123.txt",true);
后边参数为true就是 有新数据继续写
要是为false 就是 后边的数据覆盖前边的
全部回答
- 1楼网友:愁杀梦里人
- 2020-07-04 21:36
string aa = File.ReadAllText(@"文件路径", Encoding.GetEncoding("gb2312"));
这样就可以取出来了!
你可以放到textbox里看看!
然后你要怎么处理!?
- 2楼网友:孤老序
- 2020-07-31 00:13
string[] lines=File.ReadAllLine("文件位置");
foreach(string str in lines){
}
- 3楼网友:拾荒鲤
- 2020-11-07 08:16
其实实际应用中没有这样的需求,datagridview是数据源控件,主要用于做数据库数据的展示。
但是你要显式txt内的数据也可以,
先用streamreader读取文本信息,然后填充到datatable中,就可以绑定到数据源控件上了。
建议你仔细阅读一下ado.net的入门知识,以及.net常用控件的日常用法。
- 4楼网友:上分大魔王
- 2020-06-21 07:28
//FileStream fs = new FileStream("d:\\querycity.txt", FileMode.Append, FileAccess.Write);
//StreamWriter sw = new StreamWriter(fs, Encoding.Default);
//sw.WriteLine(code);
//sw.Close();
//fs.Close();
大概就是这个格式,不过这是写入,读取把writeline改成readline
- 5楼网友:底特律间谍
- 2020-04-15 07:13
StreamReader sr = new StreamReader("txt目录", Encoding.GetEncoding("GB2312"));
String line;
line = sr.ReadLine()
sr.Close();
MessageBox.Show(line );
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯