資源簡介
C#文件輸入輸出例如設置文件的屬性,只讀,隱藏等,還有創建等有關文件資源類的源代碼!

代碼片段和文件信息
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?IO
{
????public?partial?class?Form1?:?Form
????{
????????string?myfile?=?““;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????openFileDialog1.Filter?=?“文本文件(*.txt)|*.txt“;
????????????openFileDialog1.ShowDialog();
????????????StreamReader?myread?=?new?StreamReader(openFileDialog1.FileNameEncoding.Default);
????????????try
????????????{
????????????????textBox1.Text?=?““;
????????????????string?mys?=?myread.ReadLine();
????????????????while(mys!=null)
????????????????{
????????????????????textBox1.Text?=?textBox1.Text?+?mys?+?“\r\n“;
????????????????????mys?=?myread.ReadLine();//一行行讀取文件中的內容
????????????????}
????????????????myfile?=?openFileDialog1.FileName;
????????????}
????????????catch(Exception?ex)
????????????{
????????????????MessageBox.Show(“文件讀取失敗!“?+?ex.Message);
????????????}
????????????finally
????????????{
????????????????myread.Close();
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????saveFileDialog1.Filter?=?“文本文件(*.txt)|*.txt“;
????????????if(saveFileDialog1.ShowDialog()==DialogResult.OK&&saveFileDialog1.FileName!=““)
????????????{
????????????????myfile?=?saveFileDialog1.FileName;
????????????}
????????????StreamWriter?writer?=?new?StreamWriter(myfilefalseEncoding.Default);//false表示改寫內容
????????????try
????????????{
????????????????foreach?(string?line?in?textBox1.Lines)
????????????????????writer.Write(line?+?“\n“?Encoding.Default);
????????????????writer.Flush();//將緩沖的數據寫入流
????????????}
????????????catch(Exception?ex)
????????????{
????????????????MessageBox.Show(“文件保存失敗“?+?ex.Message);
????????????}
????????????finally
????????????{
????????????????writer.Close();
????????????}
????????}
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????this.Close();
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????187??2015-08-14?14:23??IO\IO\App.config
?????文件??????????0??2015-08-14?15:59??IO\IO\bin\Debug\456.doc
?????文件??????31744??2015-08-17?12:24??IO\IO\bin\Debug\IO.exe
?????文件????????187??2015-08-14?14:23??IO\IO\bin\Debug\IO.exe.config
?????文件??????75264??2015-08-17?12:24??IO\IO\bin\Debug\IO.pdb
?????文件??????24224??2015-08-17?12:27??IO\IO\bin\Debug\IO.vshost.exe
?????文件????????187??2015-08-14?14:23??IO\IO\bin\Debug\IO.vshost.exe.config
?????文件????????490??2010-03-18?12:39??IO\IO\bin\Debug\IO.vshost.exe.manifest
?????文件???????2358??2015-08-14?14:42??IO\IO\Form1.cs
?????文件???????5053??2015-08-14?14:42??IO\IO\Form1.Designer.cs
?????文件???????6224??2015-08-14?14:42??IO\IO\Form1.resx
?????文件???????1335??2015-08-14?15:09??IO\IO\Form2.cs
?????文件???????3874??2015-08-14?15:09??IO\IO\Form2.Designer.cs
?????文件???????5817??2015-08-14?15:09??IO\IO\Form2.resx
?????文件???????2263??2015-08-14?15:45??IO\IO\Form3.cs
?????文件???????5663??2015-08-14?15:45??IO\IO\Form3.Designer.cs
?????文件???????5817??2015-08-14?15:45??IO\IO\Form3.resx
?????文件???????1110??2015-08-14?17:16??IO\IO\Form4.cs
?????文件???????4153??2015-08-14?16:55??IO\IO\Form4.Designer.cs
?????文件???????6020??2015-08-14?16:55??IO\IO\Form4.resx
?????文件???????2528??2015-08-14?17:20??IO\IO\Form5.cs
?????文件??????13103??2015-08-14?17:13??IO\IO\Form5.Designer.cs
?????文件???????5817??2015-08-14?17:13??IO\IO\Form5.resx
?????文件???????2768??2015-08-17?08:47??IO\IO\Form6.cs
?????文件???????7321??2015-08-17?08:47??IO\IO\Form6.Designer.cs
?????文件???????6025??2015-08-17?08:47??IO\IO\Form6.resx
?????文件???????2164??2015-08-17?10:05??IO\IO\Form7.cs
?????文件???????8959??2015-08-17?10:05??IO\IO\Form7.Designer.cs
?????文件???????5817??2015-08-17?10:05??IO\IO\Form7.resx
?????文件???????2506??2015-08-17?12:24??IO\IO\Form8.cs
............此處省略42個文件信息
- 上一篇:asp.net醫院信息管理系統源碼
- 下一篇:C#中為treeview加背景圖
評論
共有 條評論