1
2
3
4
后台简单代码
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 FileAction { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnChooseOpenFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { txtFilePathOpen.Text = ofd.FileName; } } private void btnSave_Click(object sender, EventArgs e) { string strContent = txtInputSave.Text.Trim(); using(FileStream fs = new FileStream(txtFilePathOpen.Text, FileMode.Create)) { //将字符串转化成数组 byte[] byteFile = Encoding.UTF8.GetBytes(strContent); //要写入到文件的数据数组,从数组的第几个开始写,一共写入多少字节 fs.Write(byteFile, 0, byteFile.Length); MessageBox.Show("保存成功"); } } } }