文件二进制读

public class Access
 {
  //常量存储数据库字符串
  private const string ORACLE_STRING = "Provider=OraOLEDB.Oracle;data source=ORCL;user id=ceshi;password=ceshi;";
  
  public Access()
  {
   
  }

  public byte[] InsertYINPIN()
  { 
   FileStream stream = new FileStream(@"c:/PDOXUSRS.NET",FileMode.Open);
   int filelength = Convert.ToInt32(stream.Length);
   byte[] bytes = new byte[filelength];
   BinaryReader reader  = new BinaryReader(stream);
   for(int i = 0;i<filelength;i++)
   {
    reader.Read(bytes,0,filelength);
   } 
   reader.Close();
   stream.Close();

   int lengthone = bytes.Length;

   //存放二进制数据
   Array arr = Array.CreateInstance(typeof(System.Byte[]),5);
   //存放二进制数据
   arr.SetValue(bytes,0);
   
   //获得二进制数据
   byte[] getbytes = (byte[])arr.GetValue(0);

   int length = getbytes.Length;

   return getbytes;
  }

 

  public void BinaryToFile(byte[] binary)
  {
   try
   {
    FileStream stream = new FileStream(@"d:PDOXUSRS.NET",FileMode.Create,FileAccess.Write);
    BinaryWriter writer = new BinaryWriter(stream);
    writer.Write(binary,0,binary.Length);
    writer.Close();
    stream.Close();
    
   }
   catch(Exception ex)
   {
    throw new Exception("文件错误:"+ex.Message);
   }
  }

  /// <summary>
  /// 返回音频文件
  /// </summary>
  public Array GetSound()
  {
   using (FileStream sReader = new FileStream(@"D:/Master_Word/Music/启示录.mp3",FileMode.Open))
   {
    Array array = Array.CreateInstance(typeof(byte[]),1);
    int length = Convert.ToInt32(sReader.Length);
    byte[] bytes = new byte[length];
    BinaryReader reader = new BinaryReader(sReader);
    for(int i=0;i<length;i++)
    {
     reader.Read(bytes,0,length);
    }
    array.SetValue(bytes,0);
    return array;
   }          
  }

 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值