How best to read a File into List

后端 未结 10 1262
盖世英雄少女心
盖世英雄少女心 2020-11-27 17:34

I am using a list to limit the file size since the target is limited in disk and ram. This is what I am doing now but is there a more efficient way?

readonly         


        
10条回答
  •  一整个雨季
    2020-11-27 17:58

    //this is only good in .NET 4
    //read your file:
    List ReadFile = File.ReadAllLines(@"C:\TEMP\FILE.TXT").ToList();
    
    //manipulate data here
    foreach(string line in ReadFile)
    {
        //do something here
    }
    
    //write back to your file:
    File.WriteAllLines(@"C:\TEMP\FILE2.TXT", ReadFile);
    

提交回复
热议问题