本文介绍了拆分记事本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
在我的应用程序中,我在记事本文件中创建报告。
现在我想要的是文件大小是2.4 KB然后它应该停止处理该文件,创建一个具有相同名称的新文件并开始在那里写。
及以后打印时我必须打印所有记录来自所有文件。
例如file1.txt
line1
line2
line3
file1_1.txt
line4
line5 ..
请告诉我怎么做。
Hi all
In my application i am creating reports in notepad file.
now what i want is if the file size is 2.4 KB then it should stop coping to that file, create a new file with same name and start writing there.
and later while printing i have to print all the records from all the files.
e.g. file1.txt
line1
line2
line3
file1_1.txt
line4
line5..
Please tell me how to do that.
推荐答案
string path1 = @"D:\file1.txt";
string path2 = @"D:\file2.txt";
string newFilePath = @"D:\file3.txt";
string mergedText = System.IO.File.ReadAllText(path1);
mergedText += "\r\n";
mergedText += System.IO.File.ReadAllText(path2);
using (FileStream fs = new FileStream(newFilePath, FileMode.OpenOrCreate))
{
System.IO.File.WriteAllText(newFilePath, mergedText );
}
-KR
-KR
for (int loop=0;loop<lines.count;loop++)>
{
if(check file1 filesize<2.4)
{
//crete file1
//Write file1
}
else if(check file1 filesize>2.4)
{
//create new file2 and write it
}
}
这篇关于拆分记事本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!