Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 1.68 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I use File.ReadAllBytes In chunks
  2. string location1 = textBox2.Text;
  3.         byte[] bytes = File.ReadAllBytes(location1);
  4.         string text = (Convert.ToBase64String(bytes));
  5.         richTextBox1.Text = text;
  6.        
  7. System.IO.FileStream fs = new System.IO.FileStream(textBox2.Text, System.IO.FileMode.Open);
  8. byte[] buf = new byte[BUF_SIZE];
  9. int bytesRead;
  10.  
  11. // Read the file one kilobyte at a time.
  12. do
  13. {
  14.     bytesRead = fs.Read(buf, 0, BUF_SIZE);              
  15.     // 'buf' contains the last 1024 bytes read of the file.
  16.  
  17. } while (bytesRead == BUF_SIZE);
  18.  
  19. fs.Close();
  20.  
  21. }
  22.        
  23. using(var sr = new StreamReader(File.Open(textBox2.Text, FileMode.Open))
  24. {
  25.     while (sr.Peek() >= 0)
  26.     {
  27.         Console.WriteLine(sr.ReadLine());
  28.      }
  29. }
  30.        
  31. string location1 = textBox2.Text;
  32.     string text  = String.Empty;
  33.     using (TextReader reader = File.OpenText(location1 ))
  34.     {
  35.            do
  36.            {
  37.            string line = reader.ReadLine();
  38.                text+=line;
  39.             }
  40.             while(line!=null)
  41.  
  42.     }
  43.        
  44. var path = @"C:Tempfile.blob";
  45.  
  46.         using (Stream f = new FileStream(path, FileMode.Open))
  47.         {
  48.             int offset = 0;
  49.             long len = f.Length;
  50.             byte[] buffer = new byte[len];
  51.  
  52.             int readLen = 100; // using chunks of 100 for default
  53.  
  54.             while (offset != len)
  55.             {
  56.                 if (offset + readLen > len)
  57.                 {
  58.                     readLen = (int) len - offset;
  59.                 }
  60.                 offset += f.Read(buffer, offset, readLen);
  61.             }
  62.         }
  63.        
  64. string result = string.Empty;
  65.  
  66.             foreach (byte b in buffer)
  67.             {
  68.                 result += Convert.ToChar(b);
  69.             }