这种方法,写入到文件后,只有一个有一定大小的空文件,感觉二进制并没有成功写入,我为这个琢磨了1天半了,却找不到方法,大家来帮帮我:( OK就给分,谢谢!/// <summary>
/// 将流保存为文件
/// </summary>
/// <returns></returns>
private bool SaveStreamToFile(byte[] txtFs,string path)
{
try
{
///定义实际文件对象,保存上载的文件。
FileStream f = new FileStream(path, FileMode.CreateNew);
///把内存里的数据写入物理文件
f.Write(txtFs,0,txtFs.Length);
f.Flush();
f.Close();
f = null;
}
catch(Exception ex)
{
return false;
}
return true;
}
/// 将流保存为文件
/// </summary>
/// <returns></returns>
private bool SaveStreamToFile(byte[] txtFs,string path)
{
try
{
///定义实际文件对象,保存上载的文件。
FileStream f = new FileStream(path, FileMode.CreateNew);
///把内存里的数据写入物理文件
f.Write(txtFs,0,txtFs.Length);
f.Flush();
f.Close();
f = null;
}
catch(Exception ex)
{
return false;
}
return true;
}
/// <summary>
/// Saves the file.
/// </summary>
/// <param name="FileName">Name of the file.</param>
/// <param name="Result">The result.</param>
public void SaveFile(string FileName, byte[] Result)
{
FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate);
fs.Write(Result, 0, Result.Length);
fs.Flush();
fs.Close(); }
/// 将流保存为文件
/// </summary>
/// <returns></returns>
private bool SaveStreamToFile(MemoryStream st,string path)
{
try
{
///定义实际文件对象,保存上载的文件。
FileStream f = new FileStream(path, FileMode.OpenOrCreate);
///把内存里的数据写入物理文件
st.WriteTo(f);
f.Flush();
f.Close();
}
catch(Exception ex)
{
return false;
}
return true;
}