然后拆毕汪可以is.read读到byte数组中。旅仔
/// <summary>/// 将文件转换成byte[] 数组
/// </summary>
/// <param name="fileUrl">文件路径文件名称</param>
/// <returns>byte[]</returns>
protected byte[] GetFileData(string fileUrl)
{
FileStream fs = new FileStream(fileUrl, FileMode.Open, FileAccess.Read)
try
{
byte[] buffur = new byte[fs.Length]
fs.Read(buffur, 0, (int)fs.Length)
return buffur
}
雹迅 catch (Exception ex)
{
//MessageBoxHelper.ShowPrompt(ex.Message)
return null
}
finally
{
if (fs != null)
{
//关闭资源
fs.Close()
}
}
}
/// <summary>
/// 将文件转换成byte[] 数组源猜此
/// </summary>
/// <param name="fileUrl">文件路径文件兆纤名称</param>
/// <returns>byte[]</returns>
protected byte[] AuthGetFileData(string fileUrl)
{
using (FileStream fs = new FileStream(fileUrl, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
byte[] buffur = new byte[fs.Length]
using (BinaryWriter bw = new BinaryWriter(fs))
{
bw.Write(buffur)
bw.Close()
}
return buffur
}
}
方法一:使用fopen打开文件,不等同于将文件内容完全都到内存中。只有在使用fread时,数据才会缓存到内存中并竖。
所以,在使用fread之前,可以使用fseek来调整文件指针的位置,然后在读取5个字节就行了。
方法二:就是使用枝橡内存文件映射猛蔽旁的机理。
可以将文件的某一部分的内容映射到进程地址空间中,在读 *** 作时,就可以读取指定区间的内容了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)