File Base64 的转换

来源:互联网 发布:一号店客服软件 编辑:程序博客网 时间:2024/05/04 14:10
private void btnEncode_Click(object sender, EventArgs e){ if (!string.IsNullOrEmpty(txtInFile.Text)) { FileStream fs = new FileStream(txtInFile.Text, FileMode.Open, FileAccess.Read); byte[] filebytes = new byte[fs.Length]; fs.Read(filebytes, 0, Convert.ToInt32(fs.Length)); string encodedData = Convert.ToBase64String(filebytes, Base64FormattingOptions.InsertLineBreaks); txtEncoded.Text = encodedData; }} private void btnDecode_Click(object sender, EventArgs e){ if (!string.IsNullOrEmpty(txtOutFile.Text)) { byte[] filebytes = Convert.FromBase64String(txtEncoded.Text); FileStream fs = new FileStream(txtOutFile.Text, FileMode.CreateNew, FileAccess.Write, FileShare.None); fs.Write(filebytes, 0, filebytes.Length); fs.Close(); }}
原创粉丝点击