C#--读写文件
来源:互联网 发布:vb和c语言哪个难 编辑:程序博客网 时间:2024/05/22 17: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 WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } 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(); } }}
0 0
- 【C/C++】文件读写
- c语言读写文件
- 文件读写(c)
- C#-读写INI文件
- [C++]文件读写操作
- C#读写INI文件
- C 读写文件
- C读写ini文件
- c#FileStream文件读写
- 读写文件 c
- WinAPI C读写文件?
- C语言读写文件
- 文件读写(C++)
- c中的文件读写
- C文件读写
- c读写文件
- c读写Exc文件
- C/C++ 读写文件
- window 对象--网页上实现时间动态展示
- svn co
- checkbox使用
- [Leetcode]Validate Binary Search Tree
- 第14周oj项目1
- C#--读写文件
- C# 拷贝,移动,获取文件夹信息
- 十一月学习总结
- JDK1.5之 新特性
- java递归
- 转 -- VirtualBox 4.3.12安装ubuntu 14.04 分辨率过小问题的解决方法
- WebIM 即时通信 简介
- Android软件开发之盘点所有Dialog对话框大合集(一)
- USACO: Superprime Rib