namespace fileIncise { using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; // using System.IO; using System.Text; /// <summary> /// Incise 的摘要说明:文件切割类 /// </summary> public class Incise { /// <summary> /// 应用程序的主入口点 /// </summary> [STAThread] static void Main(string[] args) { if (args[0] == "s") { int i; FileStream fr = new FileStream(args[1], FileMode.Open, FileAccess.Read); int filesize = Convert.ToInt32(fr.Length) / Convert.ToInt32(args[2]); StreamWriter fwlist = new StreamWriter(args[1] + "." + "list", false); for (i = 1; i <= Convert.ToInt32(args[2]); i++) { byte[] byteread = new byte[filesize]; fr.Read(byteread, 0, filesize); FileStream fw = new FileStream(args[1] + "." + i, FileMode.CreateNew, FileAccess.Write); fwlist.WriteLine(args[1] + "." + i); foreach (byte bnext in byteread) fw.WriteByte(bnext); fw.Close(); } if (fr.Length != fr.Position) { byte[] byteread = new byte[Convert.ToInt32(fr.Length) - filesize * (i - 1)]; fr.Read(byteread, 0, Convert.ToInt32(fr.Length) - filesize * (i - 1)); FileStream fw = new FileStream(args[1] + "." + i, FileMode.CreateNew, FileAccess.Write); fwlist.WriteLine(args[1] + "." + i); foreach (byte bnext in byteread) fw.WriteByte(bnext); fw.Close(); } fr.Close(); fwlist.Flush(); fwlist.Close(); Console.WriteLine("文件分割结束"); } if (args[0] == "m") { StreamReader frlist = new StreamReader(args[1] + "." + "list"); FileStream fw = new FileStream(args[1], FileMode.Append, FileAccess.Write); string sline; sline = frlist.ReadLine(); while (sline != null) { FileStream fr = new FileStream(sline, FileMode.Open, FileAccess.Read); byte[] byteread = new byte[fr.Length]; fr.Read(byteread, 0, Convert.ToInt32(fr.Length)); foreach (byte bnext in byteread) fw.WriteByte(bnext); fr.Close(); sline = frlist.ReadLine(); } frlist.Close(); fw.Close(); Console.WriteLine("文件合并结束"); } } public Incise() { // // TODO: 在此处添加构造函数逻辑 // } } } 编译:csc /out:Incise.exe Incise.cs 使用:Incise s 要分割文件的文件名 分割成几个文件 如:Incise s aaa.avi 5 Incise m 合并后的文件名称 如:Incise m aaa.avi
分割程序类
最新推荐文章于 2024-04-25 16:31:48 发布