C# 文本文件读写问题
来源:互联网 发布:js jq时间段选择控件 编辑:程序博客网 时间:2024/05/22 15:42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace A42文本文件读写练习
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
buttonll.Click += buttonll_Click;
buttondq.Click += buttondq_Click;
buttonbc.Click += buttonbc_Click;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
//E:\新建文本文档.txt
string path = @textBox1.Text;
//string path = @"e:\新建文本文档.txt";
if (File.Exists(path))
{
Console.WriteLine("存在{0}文件", path);
}
else
{
MessageBox.Show("不存在" + path + "文件");
}
}
//读取按钮
private void buttondq_Click(object sender, EventArgs e)
{
textBox2.Text = null;
string path = @textBox1.Text;
try
{ //using 可以在限定范围结束自动释放资源 不用close
using (StreamReader sr = new StreamReader(path,System.Text.Encoding.Default))
{
string line;
while ((line = sr.ReadLine()) != null)
{
textBox2.Text += line+"\r\n"; //\r回车符 \n换行符
}
}
}
catch(Exception e1)
{
MessageBox.Show(e1.Message);
}
}
//浏览按钮
private void buttonll_Click(object sender, EventArgs e)
{
this.openFileDialog1.ShowDialog();
textBox1.Text = this.openFileDialog1.FileName;
}
//保存按钮
void buttonbc_Click(object sender, EventArgs e)
{
string path = @textBox1.Text;
try
{
using (StreamWriter sw = new StreamWriter(path,false, System.Text.Encoding.Default))
{
sw.Write(textBox2.Text);
}
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace A42文本文件读写练习
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
buttonll.Click += buttonll_Click;
buttondq.Click += buttondq_Click;
buttonbc.Click += buttonbc_Click;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
//E:\新建文本文档.txt
string path = @textBox1.Text;
//string path = @"e:\新建文本文档.txt";
if (File.Exists(path))
{
Console.WriteLine("存在{0}文件", path);
}
else
{
MessageBox.Show("不存在" + path + "文件");
}
}
//读取按钮
private void buttondq_Click(object sender, EventArgs e)
{
textBox2.Text = null;
string path = @textBox1.Text;
try
{ //using 可以在限定范围结束自动释放资源 不用close
using (StreamReader sr = new StreamReader(path,System.Text.Encoding.Default))
{
string line;
while ((line = sr.ReadLine()) != null)
{
textBox2.Text += line+"\r\n"; //\r回车符 \n换行符
}
}
}
catch(Exception e1)
{
MessageBox.Show(e1.Message);
}
}
//浏览按钮
private void buttonll_Click(object sender, EventArgs e)
{
this.openFileDialog1.ShowDialog();
textBox1.Text = this.openFileDialog1.FileName;
}
//保存按钮
void buttonbc_Click(object sender, EventArgs e)
{
string path = @textBox1.Text;
try
{
using (StreamWriter sw = new StreamWriter(path,false, System.Text.Encoding.Default))
{
sw.Write(textBox2.Text);
}
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
}
}
}
0 0
- C# 文本文件读写问题
- C#读写文本文件
- C#读写文本文件
- C#读写日志文本文件
- C#读写日志文本文件
- C#文本文件读写代码
- C#读写文本文件小结
- C# Stream读写文本文件
- C#读写日志文本文件
- C#读写文本文件
- C#读写文本文件
- 用C#读写文本文件
- C#读写文本文件
- c#读写文本文件
- C#文本文件(.txt)读写
- 简单的c#文本文件读写
- 简单的c#文本文件读写
- 简单的c#文本文件读写
- Python excel 读写操作
- android6.0源码分析之Camera API2.0简介
- 如何进行声明式验证之字段验证?
- ArcGIS Engine控件运行许可
- SERVLETJSP学习(五)—— 转发 、JSP开发常见问题
- C# 文本文件读写问题
- 8天学通MongoDB——第一天 基础入门
- Oracle 11gR2 RAC alert_+ASM1.log出现WARNING: failed to online diskgroup resource ora.CRS.dg (unable to
- 做点Tomcat的笔记
- 数据分析框架Pandas进阶
- echart实例
- PyCharm使用(三)—快捷键
- genymotion VT-x is disabled in the bios for both all CPU modes
- Spring+SpringMVC+MyBatis+Maven框架整合