数据一共有15条小弟我下载来保存到txt文本中每一条一个txt
数据一共有15条我下载来保存到txt文本中每一条一个txt
我在运行的时候数据又保存在同一个txt文本中了,要用什么方法才能,在我下次运行的时候txt可以重新创建
里面的txt文本不是我手动创建的是自动创建出来的;
------解决方案--------------------
------解决方案--------------------
我在运行的时候数据又保存在同一个txt文本中了,要用什么方法才能,在我下次运行的时候txt可以重新创建
里面的txt文本不是我手动创建的是自动创建出来的;
------解决方案--------------------
private void btn_Click(object sender, RoutedEventArgs e)
{
List<string> list = new List<string>();
for (int i = 0; i < 12; i++)
{
list.Add(i.ToString());
}
for (int i = 0; i < 12; i++)
{
string fileName = string.Format(@"D:\t\{0}.txt",i);
if (!File.Exists(fileName))
{
FileStream fs = File.Create(fileName);
fs.Close();
}
else
{
string[] files = Directory.GetFiles(@"D:\t\");
var v =
from s in files
where Regex.IsMatch(System.IO.Path.GetFileNameWithoutExtension(s), string.Format(@"{0}\(\d*?\)",i ))
select int.Parse(Regex.Match(s, string.Format(@"{0}\((\d*?)\)",i)).Groups[1].Value);
if (v.Count() == 0)
{
fileName = string.Format(@"D:\t\{0}({1}).txt", i, 1);
}
else
{
fileName = string.Format(@"D:\t\{0}({1}).txt", i, v.Max() + 1);
}
FileStream fs = File.Create(fileName);
fs.Close();
}
StreamWriter sw = new StreamWriter(fileName);
sw.Write(list[i]);
sw.Close();
}
}
------解决方案--------------------
/// <summary>
/// 写文件
/// </summary>
/// <param name="txt"></param>数据内容
/// <param name="filename"></param>建立文件名
public void WriteFile(string txt, string filename)