我想要读取一个子文件夹内所有的txt文件 并且把所有txt的文件中第一行的所有不一样的小标题统计到数组subtitle中,可是结果什么也没有输出 求解释 该怎么修改?
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
//filepath[] filename[]得到了文件的路径和文件的名称 数组
int i = 0, j = 0, m = 0, n = 0, h = 0;
string Path = folderBrowserDialog1.SelectedPath;
string[] filepath = System.IO.Directory.GetFiles(Path);
string[] filename = new string[filepath.Length];
string[] titleline = new string[filepath.Length];
string[] subtitle = new string[20];
for (i = 0; i < filepath.Length; i++)
{
filename[i] = System.IO.Path.GetFileNameWithoutExtension(filepath[i]);
}
//得到所有文件的标题种类
//读取一行字符串 存到titleline中
for (j = 0; j < filepath.Length; j++)
{
FileStream fn = new FileStream(filepath[j], FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fn, Encoding.Default);
titleline[j] = string.Empty;
titleline[j] = sr.ReadLine();
string[] titlearray = new string[] { };
titlearray = Regex.Split(titleline[j], @"\s+");
for (m = 0; m < titlearray.Length; m++)
{
for (n = 0; n < 20; n++)
{
if (String.Equals(titlearray[m], subtitle[n]))
{
break;
}
}
if (n == 19)
{
subtitle[h] = titlearray[m];
h++;
}
continue;
}
}
//textBox1.Text = title[8];
//title[] 为标题数组
for (int s = 0; s < subtitle.Length; s++)
{
textBox1.Text += subtitle[s] + "\r\n";
}
}
}