Fileatream表示文件流,它能够打开和关闭文件,并对文件进行单字节的读写操作。 StreamReader和StreamWriter以文本方式对流进行读写操作。建立一个文本文件,分别使用上面两种方
来源:互联网 发布:动态演示软件 编辑:程序博客网 时间:2024/06/06 23:21
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//读文件
if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
MessageBox.Show("必须输入待读文件路径及文件名");
return;
}
FileStream fs =
new FileStream(this.textBox1.Text,
FileMode.OpenOrCreate, FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, bytes.Length);
this.textBox2.Text = Encoding.UTF8.GetString(bytes);
fs.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
//写文件
if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
MessageBox.Show("必须输入待写文件路径及文件名");
return;
}
FileStream fs =
new FileStream(this.textBox1.Text,
FileMode.Create, FileAccess.Write);
byte[] bytes = Encoding.UTF8.GetBytes(this.textBox2.Text.Trim());
fs.Write(bytes, 0, bytes.Length);
fs.Dispose();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//读文件
if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
MessageBox.Show("必须输入待读文件路径及文件名");
return;
}
FileStream fs =
new FileStream(this.textBox1.Text,
FileMode.OpenOrCreate, FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, bytes.Length);
this.textBox2.Text = Encoding.UTF8.GetString(bytes);
fs.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
//写文件
if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
MessageBox.Show("必须输入待写文件路径及文件名");
return;
}
FileStream fs =
new FileStream(this.textBox1.Text,
FileMode.Create, FileAccess.Write);
byte[] bytes = Encoding.UTF8.GetBytes(this.textBox2.Text.Trim());
fs.Write(bytes, 0, bytes.Length);
fs.Dispose();
}
}
}
- Fileatream表示文件流,它能够打开和关闭文件,并对文件进行单字节的读写操作。 StreamReader和StreamWriter以文本方式对流进行读写操作。建立一个文本文件,分别使用上面两种方
- 分别使用(字符流)和(字节流)对文件进行读写操作
- 使用字符/字节流对文件进行读写操作
- FileStream读写文件【StreamWriter 和 StreamReader】
- FileStream读写文件【StreamWriter 和 StreamReader】
- FileStream读写文件【StreamWriter 和 StreamReader】
- 操作文件流的类,读写类StreamReader,StreamWriter和File类以及Directory类的操作
- (字节流、字符流)对文件进行读写操作
- 129.(字节流、字符流)对文件进行读写操作
- 通过字节流来对文件进行读写操作
- c#读写文件的几种方式StreamReader、StreamWriter、FileStream
- C#.net 用 StreamReader 和 StreamWriter 读写文件
- Java创建一个文本文件,并对其进行读写操作
- C++中对文件进行读写操作
- C++中对文件进行读写操作
- C++中对文件进行读写操作
- C++中对文件进行读写操作
- C++中对文件进行读写操作
- 构串操作符#和合并操作符##的用法
- .编写一个Windows应用程序,由给定数据25,15,10,30,20饼图
- hdu1251统计难题(字典树小试牛刀)
- Linux开启mysql远程连接的设置步骤
- 8086 寻址方式(一)CPU和主存中的寻址方式
- Fileatream表示文件流,它能够打开和关闭文件,并对文件进行单字节的读写操作。 StreamReader和StreamWriter以文本方式对流进行读写操作。建立一个文本文件,分别使用上面两种方
- Spring事务详解
- Oracle建立索引的规则
- 文件读写
- Poj 2506 Tiling
- sicp 习题2.33
- Matlab图像处理:类内、类间测试的次数控制
- ZOJ 2326 Tangled in Cables
- I/O多路复用