Answer the question
In order to leave comments, you need to log in
Why does it take a long time to convert to binary code, with a larger amount of text (112 KB file)?
private void button2_Click(object sender, EventArgs e)
{
string path = "";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
path = ofd.FileName;
}
StreamReader reader = new StreamReader(path);
byte[] buf = Encoding.UTF8.GetBytes(reader.ReadToEnd());
StringBuilder sb = new StringBuilder(buf.Length * 8);
foreach (byte b in buf)
{
sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
}
string binaryStr = sb.ToString();
textBox1.Text = binaryStr;
TextWriter tw = new StreamWriter(@"W:\du.txt");
tw.WriteLine(binaryStr);
tw.Close();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question