c# 文件转换成base64
private static void ReadFromFile() { FileStream fsForRead = new FileStream("c9a78c8a-29b0-410d-9c27-58e6be5dbccd.wav", FileMode.Open); string base64Str = ""; try { //读入一个字节 Console.Write("文件的第一个字节为:" + fsForRead.ReadByte().ToString()); Console.ReadLine(); //读写指针移到距开头10个字节处 fsForRead.Seek(0, SeekOrigin.Begin); byte[] bs = new byte[fsForRead.Length]; int log=Convert.ToInt32(fsForRead.Length); //从文件中读取10个字节放到数组bs中 fsForRead.Read(bs, 0, log); base64Str = Convert.ToBase64String(bs); Console.Write("base64编码:" + base64Str); Console.ReadLine(); } catch (Exception ex) { Console.Write(ex.Message); Console.ReadLine(); } finally { fsForRead.Close(); } }