高手们,为什么我把服务器的一个文件读取成byte,关闭所有程序,用手工操作要删掉那个文件,文件有一个进程正在使用,请先关闭进程以下是我读文件的代码:
         [WebMethod(Description="Web 服务提供的方法,返回给定文件的字节数组")]
public byte[] getfilename(string requestFileName)
{
///得到服务器端的一个文件
        if(requestFileName == null || requestFileName == "")
return new byte[0];
else
return getBinaryFile(Server.MapPath(".") + "\\"
+ requestFileName);
         
}
public byte[] getBinaryFile(string filename)
{
if(File.Exists(filename))
{
try
{
///打开现有文件以进行读取。
FileStream s = File.OpenRead(filename);
return ConvertStreamToByteBuffer(s);
s.Close();
}
catch(Exception e)
{
return new byte[0];
}
}
else
{
return new byte[0];
}
} public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
{
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
tempStream.Close();
}