这个问题弄得我昨晚都没吃饭,终于搞定了!
DirectoryInfo di = new DirectoryInfo(folderallpath);//folderallpath是目录名
FileInfo fiobj = new FileInfo(folderallpath + "\\total.obj"); // total.obj就是二进制大文件
FileStream fsobj = fiobj.Open(FileMode.Append,FileAccess.Write); //这里应该用FileMode.Append,循环写入的时候,原有文件才不会被覆盖
foreach (FileInfo fi in di.GetFiles("*.*"))
{
if (fi.Extension.ToLower() == ".jpg" ¦ ¦ fi.Extension.ToLower() == ".png" ¦ ¦ fi.Extension.ToLower() == ".tif")
{
string path = folderallpath + "/" + fi.Name;
int length = Int32.Parse(fi.Length.ToString());
if (length != 0)
{
Byte[] FileByteArray = new Byte[length];
FileStream fspic = new FileStream(path, FileMode.Open, FileAccess.Read);
fspic.Read(FileByteArray, 0, System.Convert.ToInt32(fspic.Length));
fspic.Flush();
fsobj.Write(FileByteArray,0,length);
}
}
}
fsobj.Flush();
fsobj.Close();
大功告成~~
转载于:https://www.cnblogs.com/liping19851014/archive/2008/03/12/1101760.html