1

文件读入简单操作(C#)

2

文件读入简单操作(C#)

3

文件读入简单操作(C#)

4

文件读入简单操作(C#)

后台简单代码

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("保存成功");
            }
 
        }
    }
}

  

 

 

相关文章:

  • 2018-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-08-16
  • 2022-01-15
猜你喜欢
  • 2021-10-10
  • 2022-01-02
  • 2020-01-30
  • 2021-05-21
  • 2022-01-26
  • 2021-12-07
相关资源
相似解决方案