拆分记事本文件 [英] Split a notepad file

查看:118
本文介绍了拆分记事本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



在我的应用程序中,我在记事本文件中创建报告。

现在我想要的是文件大小是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.

推荐答案

您可以使用 FileStream.SetLength [ ^ ]



将文本写入不同文件后,您可以将它们合并为

将第一个文件的文本存储在某个变量中,将第二个文件的文本存储在其他变量中等等......

然后将所有变量放在一起并保存一个新文件。很简单吧! :)

Well you can create a file with specific size using FileStream.SetLength[^]

And after writing text to the different files, you can merge them like
store 1st file's text in some variable, 2nd file's text in some other variable and so on...
Then put all variables together and save a new file. Pretty Simple huh ! :)
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


你所面临的问题是分道扬.. 。

首先你需要写一个记事本文件然后打印。



写记事本:计算记数或记录记录的数量小于文件大小是2.4 KB。所以,总是你只会写那么多的记录。如果您的记录更多,则创建一个新文件并写入新文件。



打印:您必须以编程方式处理此问题。我可以看到你正在使用像file1.txt,file1_1.txt这样的匹配方式创建文件。所以,我认为你可以轻松处理这个问题。



开始工作,如果您遇到任何问题,请向我们提问。

谢谢!
The problem you are facing make part by part.
First you have to write in a notepad file and then printing.

Writing notepad: calculate the counting or record the how amount of record is less then makes file size is 2.4 KB. So, always you will write only that amount of record. and if your record is more, then create a new file and write in new file.

Printing: You have to handle this in programmatically. I can see you are creating the file with a matching way like file1.txt, file1_1.txt. So, I think you can handle this with easily.

Start your work, If you face any problem then question us.
Thanks!


我在这里给出了基本的逻辑,以便更好地解决你的逻辑问题



string [] lines = System.IO.File.ReadAllLines(FilePath);

I'm give the basic logic here for better solution post your logic

string[] lines = System.IO.File.ReadAllLines(FilePath);
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
    }
}


这篇关于拆分记事本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆