110,545
社区成员
发帖
与我相关
我的任务
分享
string yourfilepath="你要存储的文件路径";
StreamReader reader = new StreamReader(yourfilepath);
StreamWriter writer;
int count = 0;
// string[] aa=new string[]{System.Environment.NewLine};
count = reader.ReadToEnd().Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length;
//或 while(reader .ReadLine())count++;
reader.Close();
if (count > 10000)
{
int index = yourfilepath.LastIndexOf("+");
int n ;
int.TryParse(index == -1 ? "0" : (yourfilepath.Substring(index == -1 ? 0 : index + 1)),out n);//序号
int indextemp = yourfilepath.Substring(0, index == -1 ? 0 : index).LastIndexOf("+");
string temp = yourfilepath.Substring(0, indextemp == -1 ? (yourfilepath.Length - 1) : indextemp);
string newfilepath = (n == 0 ? string.Empty : temp) + DateTime.Today.ToLongDateString() + "+" + (n + 1).ToString();
writer = new StreamWriter(newfilepath);
}
else writer = new StreamWriter(yourfilepath);
writer.WriteLine("你要存储的信息");
writer.Flush();
writer.Close();
string[]strs=textbox.Text.Split ('\n');
int a=(strs.Length%1000==0)?strs.Length:(strs.Length+1);
//存入的a文本个数
string[]str;
for(int i=0;i<a;i++)
{
//strs分成a个数组str,每个数组存一个文本
File.WriteAllLines("", str);
}