C#对象的I/O操作
来源:互联网 发布:java 前台提交post请求 编辑:程序博客网 时间:2024/05/29 18:05
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 StudentToFile
{
public partial class FrmStuToFile : Form
{
public FrmStuToFile()
{
InitializeComponent();
}
private void btnWrite_Click(object sender, EventArgs e)
{
//封装数据
Student objStu = new Student()
{
Name=this.txtName.Text.Trim(),
Age=Convert.ToInt32(this.txtAge.Text.Trim()),
Gender=this.txtGender.Text.Trim(),
Birthday=Convert.ToDateTime(this.txtBirthday.Text.Trim())
};
//保存到文件里
FileStream fs = new FileStream("F:\\myfile.txt",FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(objStu.Name);
sw.WriteLine(objStu.Age);
sw.WriteLine(objStu.Gender);
sw.WriteLine(objStu.Birthday);
sw.Close();
fs.Close();
}
private void btnRead_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("F:\\myfile.txt",FileMode.Open);
StreamReader sr = new StreamReader(fs);
Student objStu = new Student()
{
Name = sr.ReadLine(),
Age = Convert.ToInt32(sr.ReadLine()),
Gender = sr.ReadLine(),
Birthday = Convert.ToDateTime(sr.ReadLine())
};
sr.Close();
fs.Close();
this.txtName.Text=objStu.Name;
this.txtAge.Text = objStu.Age.ToString();
this.txtGender.Text = objStu.Gender.ToString();
this.txtBirthday.Text = objStu.Birthday.ToString();
}
}
}
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 StudentToFile
{
public partial class FrmStuToFile : Form
{
public FrmStuToFile()
{
InitializeComponent();
}
private void btnWrite_Click(object sender, EventArgs e)
{
//封装数据
Student objStu = new Student()
{
Name=this.txtName.Text.Trim(),
Age=Convert.ToInt32(this.txtAge.Text.Trim()),
Gender=this.txtGender.Text.Trim(),
Birthday=Convert.ToDateTime(this.txtBirthday.Text.Trim())
};
//保存到文件里
FileStream fs = new FileStream("F:\\myfile.txt",FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(objStu.Name);
sw.WriteLine(objStu.Age);
sw.WriteLine(objStu.Gender);
sw.WriteLine(objStu.Birthday);
sw.Close();
fs.Close();
}
private void btnRead_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("F:\\myfile.txt",FileMode.Open);
StreamReader sr = new StreamReader(fs);
Student objStu = new Student()
{
Name = sr.ReadLine(),
Age = Convert.ToInt32(sr.ReadLine()),
Gender = sr.ReadLine(),
Birthday = Convert.ToDateTime(sr.ReadLine())
};
sr.Close();
fs.Close();
this.txtName.Text=objStu.Name;
this.txtAge.Text = objStu.Age.ToString();
this.txtGender.Text = objStu.Gender.ToString();
this.txtBirthday.Text = objStu.Birthday.ToString();
}
}
}
阅读全文
0 0
- C#对象的I/O操作
- C# I/O操作
- c# I/O相关操作
- C# I/O操作 笔记
- C#中I/O操作
- Java I/O流操作(四)---对象的序列化
- C#笔记28:I/O操作
- java的I/O操作
- lua的I/O操作
- C++的I/O操作
- Java的I/O操作
- Java的I/O操作
- python的I/O操作
- java I/O:对象的序列化
- Java I/O 技术(三)—— 操作 字符流 的对象
- Java I/O 技术(五)—— 操作 字节流 的对象
- Java I/O 技术(八)—— 操作文件属性的对象:File
- C# 使用APM执行受I/O限制的异步操作(转)
- 查询表达式转变为elasticsearch查询语句
- vtk基础02观察者/命令机制
- Maven-maven多模块项目搭建+Dubbo分布式服务框架 budong
- 华为机试—整数与IP地址间的转换
- HTML常用标签
- C#对象的I/O操作
- 学习网站
- OpenTK教程-1绘制一个三角形
- 数据基本函数
- PAT 乙级 1016
- 边的分类
- Java集合源码剖析】HashMap源码剖析
- SIFT检测算法的实现
- jdk和tomcat环境变量配置总结