資源簡介
c#讀取txt文件,cs文件,html文件,實現用戶自定義目錄,本程序是vs2008版,2005版需要升級
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
namespace?讀取txt文件
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????public?string?filename;
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????
????????}
????????private?void?listBox1_Click(object?sender?EventArgs?e)
????????{
????????????if?(listBox1.SelectedItems.Count?==?0)
????????????{
????????????????MessageBox.Show(“您沒有選擇任何文件“);
????????????}
????????????else
????????????{
????????????????ultraTextEditor1.Text?=?““;
????????????????string?timelog?=?““;
????????????????timelog?=?listBox1.SelectedItem.ToString();
????????????????string?x?=?filename?+?“\\“?+?timelog;
????????????????StreamReader?sr?=?new?StreamReader(x);
????????????????do
????????????????{
????????????????????string?strLine?=?““;
????????????????????strLine?=?sr.ReadLine();//??讀取一行字符并返回
????????????????????ultraTextEditor1.Text?+=?strLine?+?“\r\n“;
????????????????}?while?(!sr.EndOfStream);
????????????????sr.Close();
????????????}
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????FolderBrowserDialog?folderBrowserDialog1?=?new?FolderBrowserDialog();
????????????if?(folderBrowserDialog1.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????ultraTextEditor2.Text=folderBrowserDialog1.SelectedPath;
????????????}
????????????filename?=?ultraTextEditor2.Text;
????????????if?(!File.Exists(filename))
????????????{
????????????????Directory.CreateDirectory(filename);
????????????}
????????????string?path?=?filename;
????????????System.IO.DirectoryInfo?dir?=?new?System.IO.DirectoryInfo(path);
????????????//dir.GetFiles(“*.cs“)或dir.GetFiles(“*.html“)?也支持讀取cs文件和html文件
????????????foreach?(System.IO.FileInfo?file?in?dir.GetFiles(“*.txt“))
????????????{
????????????????string?message?=?file.Name;
????????????????listBox1.Items.Add(message);
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????20480??2009-06-16?09:45??讀取txt文件\讀取txt文件\bin\Debug\讀取txt文件.exe
?????文件??????26112??2009-06-16?09:45??讀取txt文件\讀取txt文件\bin\Debug\讀取txt文件.pdb
?????文件???????5632??2005-11-11?22:25??讀取txt文件\讀取txt文件\bin\Debug\讀取txt文件.vshost.exe
?????文件???????2249??2009-06-16?09:45??讀取txt文件\讀取txt文件\Form1.cs
?????文件???????4659??2009-06-16?09:43??讀取txt文件\讀取txt文件\Form1.Designer.cs
?????文件???????6023??2009-06-16?09:43??讀取txt文件\讀取txt文件\Form1.resx
?????文件??????18401??2009-06-16?08:58??讀取txt文件\讀取txt文件\obj\Debug\ResolveAssemblyReference.cache
?????文件????????842??2009-06-16?09:43??讀取txt文件\讀取txt文件\obj\Debug\讀取txt文件.csproj.GenerateResource.Cache
?????文件??????20480??2009-06-16?09:45??讀取txt文件\讀取txt文件\obj\Debug\讀取txt文件.exe
?????文件????????485??2009-06-16?09:43??讀取txt文件\讀取txt文件\obj\Debug\讀取txt文件.exe.licenses
?????文件????????180??2009-06-16?09:43??讀取txt文件\讀取txt文件\obj\Debug\讀取txt文件.Form1.resources
?????文件??????26112??2009-06-16?09:45??讀取txt文件\讀取txt文件\obj\Debug\讀取txt文件.pdb
?????文件????????180??2009-06-16?08:49??讀取txt文件\讀取txt文件\obj\Debug\讀取txt文件.Properties.Resources.resources
?????文件????????364??2009-06-16?09:46??讀取txt文件\讀取txt文件\obj\讀取txt文件.csproj.FileList.txt
?????文件????????474??2009-06-16?08:40??讀取txt文件\讀取txt文件\Program.cs
?????文件???????1188??2009-06-16?08:40??讀取txt文件\讀取txt文件\Properties\AssemblyInfo.cs
?????文件????????164??2009-06-16?09:43??讀取txt文件\讀取txt文件\Properties\licenses.licx
?????文件???????2884??2009-06-16?08:40??讀取txt文件\讀取txt文件\Properties\Resources.Designer.cs
?????文件???????5612??2009-06-16?08:40??讀取txt文件\讀取txt文件\Properties\Resources.resx
?????文件???????1098??2009-06-16?08:40??讀取txt文件\讀取txt文件\Properties\Settings.Designer.cs
?????文件????????249??2009-06-16?08:40??讀取txt文件\讀取txt文件\Properties\Settings.settings
?????文件???????3789??2009-06-16?08:58??讀取txt文件\讀取txt文件\讀取txt文件.csproj
?????文件????????934??2009-06-16?08:40??讀取txt文件\讀取txt文件.sln
????..A..H.??????8192??2009-06-16?08:40??讀取txt文件\讀取txt文件.suo
?????目錄??????????0??2009-06-16?08:40??讀取txt文件\讀取txt文件\obj\Debug\TempPE
?????目錄??????????0??2009-06-16?08:49??讀取txt文件\讀取txt文件\bin\Debug
?????目錄??????????0??2009-06-16?09:45??讀取txt文件\讀取txt文件\obj\Debug
?????目錄??????????0??2009-06-16?08:40??讀取txt文件\讀取txt文件\bin
?????目錄??????????0??2009-06-16?08:49??讀取txt文件\讀取txt文件\obj
?????目錄??????????0??2009-06-16?09:43??讀取txt文件\讀取txt文件\Properties
............此處省略5個文件信息
- 上一篇:C#實現二叉樹基本操作,排序,計算和文件讀寫
- 下一篇:用C#做的鮮花管理系統
評論
共有 條評論