
Untitled
By: a guest on
Aug 10th, 2012 | syntax:
None | size: 1.68 KB | hits: 12 | expires: Never
How do I use File.ReadAllBytes In chunks
string location1 = textBox2.Text;
byte[] bytes = File.ReadAllBytes(location1);
string text = (Convert.ToBase64String(bytes));
richTextBox1.Text = text;
System.IO.FileStream fs = new System.IO.FileStream(textBox2.Text, System.IO.FileMode.Open);
byte[] buf = new byte[BUF_SIZE];
int bytesRead;
// Read the file one kilobyte at a time.
do
{
bytesRead = fs.Read(buf, 0, BUF_SIZE);
// 'buf' contains the last 1024 bytes read of the file.
} while (bytesRead == BUF_SIZE);
fs.Close();
}
using(var sr = new StreamReader(File.Open(textBox2.Text, FileMode.Open))
{
while (sr.Peek() >= 0)
{
Console.WriteLine(sr.ReadLine());
}
}
string location1 = textBox2.Text;
string text = String.Empty;
using (TextReader reader = File.OpenText(location1 ))
{
do
{
string line = reader.ReadLine();
text+=line;
}
while(line!=null)
}
var path = @"C:Tempfile.blob";
using (Stream f = new FileStream(path, FileMode.Open))
{
int offset = 0;
long len = f.Length;
byte[] buffer = new byte[len];
int readLen = 100; // using chunks of 100 for default
while (offset != len)
{
if (offset + readLen > len)
{
readLen = (int) len - offset;
}
offset += f.Read(buffer, offset, readLen);
}
}
string result = string.Empty;
foreach (byte b in buffer)
{
result += Convert.ToChar(b);
}