编程题

(上机实验题在最后!)
----------------------------------------------分割线------------------------------------------------------------------------------

存储

存储----存储----存储

// An highlighted block
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 exci12
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string path = "F:\\MyTest1.txt";//文件名if (File.Exists(path))File.Delete(path);else{FileStream fs = File.OpenWrite(path);StreamWriter sw = new StreamWriter(fs,Encoding.Default);sw.WriteLine(textBox1.Text);sw.Close();fs.Close();}}}
}

读取

// An highlighted block
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 exci12
{public partial class Form2 : Form{public Form2(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string path = "F:\\MyTest1.txt";//文件名string mystr = "";FileStream fs = File.OpenRead(path);StreamReader sr = new StreamReader(fs, Encoding.Default);//指定打开文件//将文件流指针定位在开始位置fs.Seek(0,SeekOrigin.Begin);while (sr.Peek() > -1)mystr = mystr + sr.ReadLine() + "/r/n";sr.Close();fs.Close();textBox1.Text = mystr;}}
}

上机实验题

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 WindowsFormsApplication1
{public partial class Form1 : Form{string path = "D:\\MyTest1.txt";public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){if (File.Exists(path))File.Delete(path);else{StreamWriter sw = File.CreateText(path);sw.Close();FileStream fs = File.OpenWrite(path);StreamWriter sb = new StreamWriter(fs, Encoding.Default);sb.WriteLine(textBox1.Text);sb.WriteLine(textBox2.Text);sb.WriteLine(textBox3.Text);sb.WriteLine(textBox4.Text);sb.WriteLine(textBox5.Text);sb.Close();}}private void Form1_Load(object sender, EventArgs e){textBox1.Text = "";textBox2.Text = "";textBox3.Text = "";textBox4.Text = "";textBox5.Text = "";textBox6.Text = "";}private void button2_Click(object sender, EventArgs e){int i;string mystr = "学号\t姓名\t性别\t年龄\t分数\r\n";FileStream fs = File.OpenRead(path);StreamReader sr = new StreamReader(fs, Encoding.Default);fs.Seek(0, SeekOrigin.Begin);while (sr.Peek() > -1){for (i = 0; i < 5; i++)mystr = mystr + sr.ReadLine() + "\t";mystr = mystr + "\r\n";}sr.Close();fs.Close();textBox6.Text = mystr;}}
}

C#程序设计第三版(李春葆)第12章文件操作课后习题答案相关推荐

  1. 浙大版《C语言程序设计》第四版(何钦铭颜晖) 第4章 循环结构 课后习题答案

    浙大版<C语言程序设计>第四版(何钦铭颜晖) 第4章 循环结构 课后习题答案 你也可以上程序咖(https://meta.chengxuka.com),打开大学幕题板块,不但有答案,讲解, ...

  2. python课本答案上海交大第五章_高等数学课后习题答案上海交大版完整版非常详细_.pdf...

    高等数学课后习题答案上海交大版完整版非常详细_ 一诺整理 一诺整理 一一诺诺整整理理 高等数学 高等数学 课后习题答案 课后习题答案 (上海交大版) (上海交大版) ((上上海海交交大大版版)) /w ...

  3. 浙大版《C语言程序设计》第四版(何钦铭颜晖) 第3章 分支结构 课后习题答案

    你也可以上程序咖(https://meta.chengxuka.com),打开大学幕题板块,不但有答案,讲解,还可以在线答题. 一.选择题 1.有一函数 y={1(x>0)0(1=0)−1(x& ...

  4. c语言程序设计教程第二版李春葆,C语言程序设计教程.第2版

    摘要: 本书将C语言程序设计分成入门基础,程序设计的基本结构,模块化程序设计的结构3个循序渐进的部分.主要介绍C语言程序的基本结构,数据的表达方式,基本表达式语句等内容.书中以实例导入,以程序为核心, ...

  5. python程序设计第三版约翰策勒第六章编程练习答案

    第一题 def lrc(animal, call):m()print("And on his farm he had a {0}, Ee I Ee I Oh!".format(an ...

  6. 算法分析与设计第二版(李春葆)第六章分支界限法

    分支界限法类似于回溯法,一般回溯法目标是找出所有解,二分支界限法是找出满足条件的一个解或者最优解 算法 解空间树搜索方式 存储结点的常用数据结构 结点存储特性 常用应用 回溯法 深度优先搜索 栈 活结 ...

  7. 《C语言程序设计》第4版 何钦铭、颜晖主编 课后习题答案 第8章 习题8

    一.选择题 1~4 B C A D 5~8 C B A B 二.填空题 1.a  10  &maxskub  &minsub             *maxsub=i        ...

  8. 《C语言程序设计》第4版 何钦铭、颜晖主编 课后习题答案 第4章 习题4

    习题4 P092~P097 一.选择题 1~6 DCACDA 二.填空题 13    22 14#4# s1=6    s2=3 t*10 1#2#    1#2#4#5#6# 04ufd! (1) ...

  9. 《C语言程序设计》第4版 何钦铭、颜晖主编 课后习题答案 第5章 习题5

    P118~122 一.选择题 1~6  D B C A D C 二.填空题 1.2#3#5#7# 2.int fun(int m)           fun(n)           int m  ...

最新文章

  1. 安装脚本退出,并显示错误:命令“ x86_64-linux-gnu-gcc”失败,退出状态为1
  2. 统计dataframe中所有列的null数量与填充null注意事项
  3. 【计算机图形学】实验:C#.net环境下采用GDI+图形特技处理案例教程
  4. 使用CDI的InjectionPoint注入配置值
  5. docbook_DocBook简介,一种值得学习的灵活标记语言
  6. linux 测试本地端口是否打开,有效地测试Linux上的端口是否打开?
  7. 关于离散数学的一点事情
  8. 隐藏 console 窗口
  9. zabbix3.4详细安装教程
  10. 软件工程--可行性研究
  11. web开发路径问题解决
  12. 成长篇-靡有不凡鲜克有终-02
  13. 外地父母常住北京-医疗问题-新农合北京就医实时结算
  14. websocket协议与实现原理
  15. AAA与AAM指令代码实验
  16. 水利部水利工程造价系统
  17. 性能监控:top命令
  18. CORBA 简单了解和JAVA与C++互操以及C++调用Java web service
  19. H. 知识图谱 知识问答
  20. 音效codec芯片解决方案

热门文章

  1. 腹有诗书气自华——记环宇通软CEO骆永华 1
  2. 思绪,飘在青山绿水间
  3. 蚂蚁金服缘何自研Service Mesh?
  4. html 动态加载的菜单 当菜单点击一下,打开接着又关闭
  5. 对话混沌创新商学院6期校友:“朋克养生”背后的产业密码
  6. 朝向look at和lookRotation
  7. 腾讯云轻量应用服务器搭建网站
  8. 34岁IBM工程师电脑被抢身亡:以命相争背后,是无处安放的生活
  9. 深度学习双显卡配置_更新深度学习装备:双(1080Ti)显卡装机实录
  10. iphone已停用连接itunes怎么解锁教程