C# byte[]和文件FileStream相互转化-DESTLIVEusing System.IO;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE
//读filename到byte[]
C# byte[]和文件FileStream相互转化-DESTLIVE

C# byte[]和文件FileStream相互转化-DESTLIVE        
private byte[] ReadFile(string fileName)
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            FileStream pFileStream 
= null;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
byte[] pReadByte = new byte[0];
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
try
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                pFileStream 
= new FileStream(fileName, FileMode.Open, FileAccess.Read);
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                BinaryReader r 
= new BinaryReader(pFileStream);
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                r.BaseStream.Seek(
0, SeekOrigin.Begin);    //将文件指针设置到文件开
C# byte[]和文件FileStream相互转化-DESTLIVE

C# byte[]和文件FileStream相互转化-DESTLIVE                pReadByte 
= r.ReadBytes((int)r.BaseStream.Length);
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                
return pReadByte;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
catch
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                
return pReadByte;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
finally
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                
if (pFileStream != null)
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                    pFileStream.Close();
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        
//写byte[]到fileName
C# byte[]和文件FileStream相互转化-DESTLIVE

C# byte[]和文件FileStream相互转化-DESTLIVE        
private bool writeFile(byte[] pReadByte, string fileName)
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            FileStream pFileStream 
= null;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE 
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
try
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                pFileStream 
= new FileStream(fileName, FileMode.OpenOrCreate);
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                pFileStream.Write(pReadByte, 
0, pReadByte.Length);
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE 
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
catch
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                
return false;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
finally
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                
if (pFileStream != null)
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                    pFileStream.Close();
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
return true;
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE         测试
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        
private void button6_Click(object sender, EventArgs e)
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE             
//by 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2007.11.23
C# byte[]和文件FileStream相互转化-DESTLIVE

C# byte[]和文件FileStream相互转化-DESTLIVE 
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE
byte[] b = ReadFile(@"c:\u.jpg");
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
if (writeFile(b, @"c:\u1.jpg"))
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
{
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE                MessageBox.Show(
"成功");
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE            
else { MessageBox.Show("失败"); }
C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE        }

C# byte[]和文件FileStream相互转化-DESTLIVE
C# byte[]和文件FileStream相互转化-DESTLIVE