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;
}
}
}