摘要:(2010-08-06) C#.NET System.IO
范列1.读取图档后存档
程序
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;namespace winmod05{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private voID button1_Click(object sender,EventArgs e) { //呈现对话盒 if (this.openfileDialog1.ShowDialog() == DialogResult.OK) { //文件名称 //MessageBox.Show(this.openfileDialog1.filename); //1.建立串流 System.IO.Stream fs1 = new System.IO.fileStream(this.openfileDialog1.filename,System.IO.fileMode.Open,System.IO.fileAccess.Read); //准备缓冲区 Byte数组 Byte[] buff = new Byte[fs1.Length]; //开始读取 读到缓冲区去 fs1.Read(buff,(Int32)fs1.Length); //建立Gap(内存串流) System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Write(buff,(Int32)fs1.Length); //建构Image对象 System.Drawing.Image img = new System.Drawing.Bitmap(ms); //设定PictureBox this.pictureBox1.Image = img; //写出图片到另一个地方 //建立串流 String newfile=System.IO.Path.GetfilenameWithoutExtension(this.openfileDialog1.filename)+"_new.jpg"; //MessageBox.Show(newfile); System.IO.Stream fout = new System.IO.fileStream(@"c:images" + newfile,System.IO.fileMode.Create,System.IO.fileAccess.Write); //写出去 fout.Write(buff,(Int32)fs1.Length); //清缓冲区 fout.Flush(); fout.Close(); //关闭串流 fs1.Close(); } } }}
范列2.笔记本 读档与写档
程序
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;namespace winmod05{ public partial class NotePad : Form { public NotePad() { InitializeComponent(); } private voID button1_Click(object sender,EventArgs e) { //启动对话盒 if (this.openfileDialog1.ShowDialog() == DialogResult.OK) { //处理 //1.建立串流 System.IO.Stream fs1 = new System.IO.fileStream(this.openfileDialog1.filename,System.IO.fileAccess.Read); //2.接上读取器 System.IO.TextReader reader = new System.IO.StreamReader(fs1,System.Text.EnCoding.UTF8); String text = reader.ReadToEnd(); this.textBox1.Text = text; fs1.Close(); } } private voID button2_Click(object sender,EventArgs e) { // if (this.savefileDialog1.ShowDialog() == DialogResult.OK) { //保存 //1.建立串流 System.IO.Stream fs1 = new System.IO.fileStream(this.savefileDialog1.filename,System.IO.fileAccess.Write); //2.建立Writer System.IO.StreamWriter writer = new System.IO.StreamWriter(fs1,System.Text.EnCoding.UTF8); writer.Write(this.textBox1.Text); writer.Flush(); writer.Close(); fs1.Close(); } } }}
补充:
原文:大专栏 (2010-08-11) C#.NET System.IO
总结以上是内存溢出为你收集整理的(2010-08-11) C#.NET System.IO全部内容,希望文章能够帮你解决(2010-08-11) C#.NET System.IO所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)