把mp3文件编码为base64, 然后再把base64为转换为mp3

来源:互联网 发布:淘宝司法拍卖房产网址 编辑:程序博客网 时间:2024/05/17 09:34
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2{    class Program    {        static void Main(string[] args)        {            System.Text.Encoding encode = System.Text.Encoding.ASCII;            FileStream fileStreamObj;            FileInfo fileInfoObj = new FileInfo(@"H:\New folder (7)\ConsoleApplication1\ConsoleApplication2\test.mp3");            fileStreamObj = fileInfoObj.OpenRead();//.OpenWrite();            byte[] bytedata = new byte[fileInfoObj.Length];            fileStreamObj.Read(bytedata, 0, bytedata.Length);            fileStreamObj.Flush();            fileStreamObj.Close();            string audioBase64Result = Convert.ToBase64String(bytedata, 0, bytedata.Length);            byte[] audioByteArray = Convert.FromBase64String(audioBase64Result);            //fileStreamObj.Write(audioByteArray, 0, audioByteArray.Length);            //MemoryStream ms = new MemoryStream(audioByteArray);            var mp3File = File.Create(@"H:\New folder (7)\ConsoleApplication1\ConsoleApplication2\testResult.mp3", audioByteArray.Length);            mp3File.Write(audioByteArray, 0, audioByteArray.Length);            mp3File.Flush();            mp3File.Close();        }    }}

0 0
原创粉丝点击