Click here to Skip to main content
15,914,642 members
Home / Discussions / C#
   

C#

 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Inbaljona4-Dec-08 1:57
Inbaljona4-Dec-08 1:57 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Simon P Stevens4-Dec-08 2:02
Simon P Stevens4-Dec-08 2:02 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Inbaljona4-Dec-08 2:07
Inbaljona4-Dec-08 2:07 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Dave Kreskowiak4-Dec-08 2:18
mveDave Kreskowiak4-Dec-08 2:18 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Nissim Salomon4-Dec-08 2:09
Nissim Salomon4-Dec-08 2:09 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Inbaljona4-Dec-08 2:27
Inbaljona4-Dec-08 2:27 
GeneralRe: Read specific lines from txt file and write them to another file Pin
Nissim Salomon4-Dec-08 2:48
Nissim Salomon4-Dec-08 2:48 
GeneralRe: Read specific lines from txt file and write them to another file Pin
User 43300284-Dec-08 4:43
User 43300284-Dec-08 4:43 
I recommend to you to do it on the fly, like other people is saying

The only thing you must be care about is to make the stream flush to prevent memory problems, i mean
void CopyLines(string inFile, string outFile){
    StreamReader sr = new StreamReader(File.Open(inFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
    StreamWriter sw = new StreamWriter(outFile);
    string line;
    while (!sr.EndOfStream) {
        line = sr.ReadLine();
        if ( Match(line) ) {
            sw.WriteLine(line);
        }
        sw.Flush();
    }
    sr.Close();
    sw.Close();
}


Maybe the Flush method should be not always called, i mean like if (i % 100 == 0) sw.Flush(), or use the AutoFlush property

Saludos!!

____Juan

Question[Message Deleted] Pin
tonyjsebastian14-Dec-08 1:33
tonyjsebastian14-Dec-08 1:33 
AnswerRe: .net in Linux Pin
J4amieC4-Dec-08 1:38
J4amieC4-Dec-08 1:38 
AnswerRe: .net in Linux PinPopular
Simon P Stevens4-Dec-08 1:40
Simon P Stevens4-Dec-08 1:40 
GeneralRe: .net in Linux Pin
tonyjsebastian14-Dec-08 2:02
tonyjsebastian14-Dec-08 2:02 
GeneralRe: .net in Linux Pin
Simon P Stevens4-Dec-08 2:05
Simon P Stevens4-Dec-08 2:05 
GeneralRe: .net in Linux Pin
tonyjsebastian14-Dec-08 2:13
tonyjsebastian14-Dec-08 2:13 
GeneralRe: .net in Linux Pin
Simon P Stevens4-Dec-08 2:54
Simon P Stevens4-Dec-08 2:54 
GeneralRe: .net in Linux Pin
Dave Kreskowiak4-Dec-08 2:15
mveDave Kreskowiak4-Dec-08 2:15 
GeneralRe: .net in Linux Pin
tonyjsebastian14-Dec-08 2:30
tonyjsebastian14-Dec-08 2:30 
GeneralRe: .net in Linux Pin
EliottA4-Dec-08 2:45
EliottA4-Dec-08 2:45 
GeneralRe: .net in Linux Pin
Pr@teek B@h!4-Dec-08 5:24
Pr@teek B@h!4-Dec-08 5:24 
Question[Message Deleted] Pin
tonyjsebastian14-Dec-08 0:55
tonyjsebastian14-Dec-08 0:55 
AnswerRe: tooltip for textbox Pin
Simon P Stevens4-Dec-08 1:14
Simon P Stevens4-Dec-08 1:14 
QuestionQuestion in microsoft word library Pin
hatan864-Dec-08 0:48
hatan864-Dec-08 0:48 
AnswerRe: Question in microsoft word library Pin
Ashfield4-Dec-08 1:23
Ashfield4-Dec-08 1:23 
Questiondatagrid detect cell changed Pin
swjam4-Dec-08 0:35
swjam4-Dec-08 0:35 
Question[Message Deleted] Pin
tonyjsebastian14-Dec-08 0:28
tonyjsebastian14-Dec-08 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.