C# 读写文件
来源:互联网 发布:金蛇雾化器做丝数据 编辑:程序博客网 时间:2024/05/18 08:52
//Stream流读写文件:
private void button3_Click(object sender, EventArgs e)
{
//将textBox3.Text写入nihao.txt文件
Stream s = new FileStream("nihao.txt",FileMode.Create,FileAccess.Write);
//打开模式,访问方式
StreamWriter sw = new StreamWriter(s, Encoding.Default);//创建Stream流,指定编码方式
sw.Write(textBox3.Text);
sw.Close();
}
private void button2_Click(object sender, EventArgs e)
{
//将nihao.txt文件读出到textBox3.Text
Stream s = new FileStream("nihao.txt", FileMode.Open);
StreamReader sr = new StreamReader(s,Encoding.Default);
textBox3.Text= sr.ReadToEnd().ToString();
sr.Close();
s.Close();
//sr.BaseStream的Position或Seek()可移动文件流指针到的任意位置。
}
//二进制文件的读写:
private void button5_Click(object sender, EventArgs e)
{
Stream s = new FileStream("nihao1.txt", FileMode.Create);
BinaryWriter sw = new BinaryWriter(s, Encoding.Unicode);
sw.Write(textBox3.Text);
sw.Close();
}
private void button6_Click(object sender, EventArgs e)
{
// MessageBox.Show(Convert.ToChar(97).ToString());
Stream s = new FileStream("nihao1.txt", FileMode.Open);
BinaryReader sr = new BinaryReader(s, Encoding.Unicode);
textBox3.Text=sr.ReadString().ToString();
sr.Close();
s.Close();
}
- C#读写INI文件
- C#读写INI文件
- C#读写INI文件
- C#读写INI文件
- c#读写xml文件
- c#读写xml文件
- c#读写xml文件
- C#读写文件
- C# 文件读写
- C#读写xml文件
- c#读写ini文件
- C#读写INI文件
- c#读写xml文件
- C#读写xml文件
- c# 读写xml文件
- C#读写xml文件
- C#读写xml文件
- C#读写中文文件
- Sprint 1&2 总结
- Dom学习3:非w3c标准的强大的innerHTML及标准DOM生成HTML
- asp.net跳转页面的三种方法比较
- fatal error C1010: unexpected end of file while looking for precompiled header directive
- asp.net国际化,页面选择语言
- C# 读写文件
- C# 学习网站
- 各种基本算法实现小结(三)—— 树与二叉树
- 继续谈JAVA虚拟机
- 各种基本算法实现小结(四)—— 图及其遍历
- qt 槽与信号
- SQL 语句学习
- 各种基本算法实现小结(五)—— 排序算法
- VB无所不能之七:VB的多线程(2)