code_junkie

Reading from file not fast enough, how would I speed it up?

Nov 11th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public static string readFile(string path)
  2. {
  3. StringBuilder stringFromFile = new StringBuilder();
  4. StreamReader SR;
  5. string S;
  6. SR = File.OpenText(path);
  7. S = SR.ReadLine();
  8. while (S != null)
  9. {
  10. stringFromFile.Append(SR.ReadLine());
  11. }
  12. SR.Close();
  13. return stringFromFile.ToString();
  14. }
  15.  
  16. public static string readFile(string path)
  17. {
  18.  
  19. return File.ReadAllText(path);
  20.  
  21. }
  22.  
  23. S = SR.ReadLine();
  24. while (S != null)
  25. {
  26. stringFromFile.Append(SR.ReadLine());
  27. }
  28.  
  29. S = SR.ReadLine();
  30. while (S != null)
  31. {
  32. stringFromFile.Append(S = SR.ReadLine());
  33. }
  34.  
  35. S = SR.ReadLine();
  36. while (S != null){
  37. stringFromFile.Append(S);
  38. S = SR.ReadLine();
  39. }
  40.  
  41. return System.IO.File.ReadAllText(path);
  42.  
  43. var str = System.IO.File.ReadAllText(path);
  44. return str.Replace(Environment.NewLine, "");
  45.  
  46. var info = new FileInfo(path);
  47. var sb = new StringBuilder((int)info.Length);
Add Comment
Please, Sign In to add comment