110,015
社区成员




System.IO.FileSystemWatcher watch = new System.IO.FileSystemWatcher("目录名","文件名");
System.IO.FileSystemWatcher watch = new System.IO.FileSystemWatcher("E:\\","aa.txt");
watch.Changed += new System.IO.FileSystemEventHandler(watch_Changed);
watch.EnableRaisingEvents = true;
void watch_Changed(object sender, System.IO.FileSystemEventArgs e)
{
//TODO..
}
string filePath = "你的路径";
using (StreamReader sr = new StreamReader(filePath))
{
string temp = "";
while (sr.EndOfStream)
{
if (String.IsNullOrEmpty(temp))
{
temp = sr.ReadLine();
temp = temp.Substring(1);
}
else
{
string t = sr.ReadLine();
string path = Path.Combine(new FileInfo(filePath).DirectoryName,t.Split(',')[0] + ".txt");
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine(t);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(@"E:\test.txt");//test.txt:原始文件
string headText = reader.ReadLine();//先读出第一行,用作标题
//接着读下面的内容,直到读完
while (!reader.EndOfStream)
{
string str = reader.ReadLine(); //读取一行
StreamWriter sw = new StreamWriter("E:\\" + str.Substring(0, str.IndexOf(",")) + ".txt");//创建文件(文件名用第一个','前的内容)
sw.WriteLine(headText);//向文件写标题
sw.WriteLine(str);//写该行内容
sw.Close();//关闭流
}
}
StreamReader reader = new StreamReader(@"E:\test.txt");
string[] str = System.Text.RegularExpressions.Regex.Split(reader.ReadToEnd(),@"\r\n");//把文本内容按行保存在str数组中
string lastLine = str[str.Length-1];//最后一行
private void button1_Click(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(@"E:\test.txt");//test.txt:原始文件
string headText = reader.ReadLine();
while (!reader.EndOfStream)
{
string str = reader.ReadLine();
StreamWriter sw = new StreamWriter("E:\\" + str.Substring(0, str.IndexOf(",")) + ".txt");
sw.WriteLine(headText);
sw.WriteLine(str);
sw.Close();
}
}