1、写入流
string filename = saveFileDialog1.FileName; //写入流,可以在硬盘上创建文件,并为文件写入信息 StreamWriter sw = new StreamWriter(filename); sw.Write(this.textBox1.Text); //this:代表的它所在的那个类当前对象 sw.Close(); (1)、点击写入 (2)、找到文件,打开
2、读入流:
openFileDialog1.Filter="文本文档|*.txt|所有文件|*.*"; //设置读取格式 openFileDialog1.ShowDialog(); //打开对话框
string filename = openFileDialog1.FileName; //通过读入流进行文件读取 StreamReader sr = new StreamReader(filename); textBox1.Text = sr.ReadToEnd(); //ReadToEnd从头读到尾 sr.Close(); //关闭流
(1).点击打开 (2)、选中显示
3、FileStream:(用控件pictureBox)
专门用于程序与硬盘之间文件读写的操作,
//文件流 FileStream fs = new FileStream(openFileDialog1.FileName,FileMode.Open,FileAccess.Read); Image img = System.Drawing.Bitmap.FromStream(fs); pictureBox1.Image = img;
4、图片类:
二进制数据的话:bianaryReader
FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); byte[] buffer = br.ReadBytes(int.Parse(fs.Length.ToString())); 5、MemoryStream:用于程序和内存之间进行操作数据,一般用于程序和数据库中间的中转
转载于:https://www.cnblogs.com/tzq9308/p/4350694.html