美文网首页
数据流基础之写文件和读文件

数据流基础之写文件和读文件

作者: lizg | 来源:发表于2018-12-09 19:55 被阅读9次

创建一个窗体应用程序,拖动两个TextBox空间,其中一个具有Multiline=true的属性,拖动两个Button按钮,一个命名为写入文件,一个读取文件

写入文件按钮的代码

       private void btn_write_Click(object sender, EventArgs e)
        {
            string path = @tbx_path.Text.Trim();

            string content = tbx_write.Text;
            FileStream fswriter = new FileStream(path, FileMode.Create, FileAccess.Write);
            byte[] array = Encoding.UTF8.GetBytes(content);
            fswriter.Write(array, 0, array.Length);
            MessageBox.Show("文件写入成功!");
            fswriter.Close();
            fswriter.Dispose();
        }

读取文件按钮的代码

private void btn_read_Click_Click(object sender, EventArgs e)
{
            string path = tbx_path.Text;

            using (FileStream fsReader = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                byte[] array = new byte[1024];
                fsReader.Read(array, 0, (int)fsReader.Length);
                tbx_write.Text = Encoding.UTF8.GetString(array);
            }
     
}

相关文章

  • 数据流基础之写文件和读文件

    创建一个窗体应用程序,拖动两个TextBox空间,其中一个具有Multiline=true的属性,拖动两个Butt...

  • python基础之读文件

    python基础之读文件

  • 13. python文件和流

    读文件和写文件 管道输出 读行和写行 使用FileInput对象读取文件 读文件和写文件 管道输出 模拟了一个gr...

  • Python-文件操作

    字符编码 文件操作 基础读 基础写 with语法 操作模式 游标操作 文件的遍历 字符编码: 三种字符串: 文件操...

  • Python ☞ day 10

    Python学习笔记之 自动化办公与鼠标键盘模拟 读写csv文件 读csv文件 写csv文件 读取PDF文件 读...

  • Hadoop系列008-HDFS的数据流

    HDFS写数据流程 1.1 剖析文件写入 1)客户端向namenode请求上传文件,namenode检查目标文件是...

  • Linux 写文件时 何时 flush buffer

    遇到了一个很奇怪的问题,读文件失败。尤其是想要读取特别小的文件的时候。 流程是: 数据流 -> 存入文件 -> 读...

  • go 文件操作

    File 建立File内存地址 打开文件 写文件 读文件 删除文件 判断文件是否存在 file写文件 file读文...

  • java读写文件

    读文件 写文件

  • 文件操作

    打开文件 读 关闭文件 写文件

网友评论

      本文标题:数据流基础之写文件和读文件

      本文链接:https://www.haomeiwen.com/subject/gimkhqtx.html