Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello
currently I am working on a small application which shall handle greate Textfiles.
How to read and interprete the content is actually no Problem but I also want to save the file very efficient (No working times over 10~15sec). The greatest file is about 500Mb big.

What I basically want to do is to edit several line in the file.

regards
Posted

There really isn't much option: you can write the whole revised file each time, or you can write the file from the point of the first modification onwards.

The problem is that text files don't understand lines - the content is just a sequence of characters to them - so if you insert or delete a single character every single character from the point to the end of the file has to be moved. There is no function for "insert text here" or "delete this text" because there is no structure or organisation to the file.

So if your file write is taking 10 seconds, then it will take 10 seconds - that's how long it takes to get the data written to the HDD.

The only thing you can do is either structure you dtaa so that you can insert and deleted portions (unlikely) or move the write code into a background task so that it proceeds without the user noticing it is still going on.
 
Share this answer
 
To speed up things, I believe you have to load in memory (and elaborate) large chunks of the file (or the whole file, if you can).
 
Share this answer
 
Thanks so far.
Some Facts about my application:
The file xy.txt look like:
Bla blabla blablabla

I basically use the Split function to read through the txt
C#
string txt = "Bla blabla blablabla"; //Just a example actually I am reading a extern file
string[] word = text.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);

Now I go through the Array an search for certain text like blabla if the line contains this text I want to delete it
so far so good.
My idea is to fill all lines which not contain this text in a list and after the Streamreader is finished I want to rewrite the file with the Content of the list.

What do you think of it ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900