C#自适应合并文件的方法

本文实例讲述了C#自适应合并文件的方法。分享给大家供大家参考。具体实现方法如下:

using System;
using System.IO;
namespace MergeFile
{
  class Program
  {
    public static void Main(string[] args)
    {
      int count=1;
      string sourcepath=@"D:\SplitFile";
      string filetomerge=@"C:\编程的奥秘.pdf";
      FileStream ftm = new FileStream(filetomerge, FileMode.Create, FileAccess.Write);
      BinaryWriter bw=new BinaryWriter(ftm);
      string filepath;
      while(File.Exists(filepath=sourcepath+Path.DirectorySeparatorChar+Path.GetFileName(filetomerge)+count++))
      {
        FileStream fsr = new FileStream(filepath, FileMode.Open, FileAccess.Read);
        BinaryReader br=new BinaryReader(fsr);
        bw.Write(br.ReadBytes((int)fsr.Length));
        br.Close();
        fsr.Close();
      }
      bw.Flush();
      bw.Close();
      ftm.Close();
    }
  }
}

希望本文所述对大家的C#程序设计有所帮助。

(0)

相关推荐

  • C#实现合并多个word文档的方法

    本文实例讲述了C#实现合并多个word文档的方法,是非常具有实用价值的技巧.分享给大家供大家参考. 具体实现方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.Office.Interop.Word; using System.Reflection; using System.IO; using System.Diagnostics;

  • C# 合并GriewView相同列的小例子

    复制代码 代码如下: /// <summary>     /// 合并GridView中某列相同信息的行(单元格)     /// </summary>     /// <param name="GridView1"></param>     /// <param name="cellNum"></param>     public static void GroupCol(GridView G

  • c#中合并DataTable重复行的值

    复制代码 代码如下: //DataTable数据添加            Hashtable ht = new Hashtable();            DataTable dt = new DataTable();            DataColumn dc = new DataColumn("id");            dt.Columns.Add(dc);            dc = new DataColumn("name");   

  • C#逐行读取文件的方法

    本文实例讲述了C#逐行读取文件的方法.分享给大家供大家参考.具体如下: 这里使用C#逐行读取文件,对于大文件的读取非常有用. StreamReader sr = new StreamReader("fileName.txt"); string line; while((line= sr.ReadLine()) != null) { Console.WriteLine("xml template:"+line); } if (sr != null)sr.Close()

  • C#实现TIF图像转PDF文件的方法

    本文实例讲述了C#实现TIF图像转PDF文件的方法.分享给大家供大家参考.具体实现方法如下: 这里介绍使用TIFtoPDF的用法.该工具可以将多个TIF图像文件合并成一个PDF文件 TIFtoPDF.rar文件点击此处本站下载. Program.cs文件如下: using System; using System.Collections.Generic; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; usi

  • C#通过流写入数据到文件的方法

    本文实例讲述了C#通过流写入数据到文件的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.IO; public class WriteFileStuff { public static void Main() { FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWr

  • C#文件合并的方法

    本文实例讲述了C#文件合并的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.IO; string filetomerge=@"C:\temp\data.bin"; string targetpath=@"D:\store"; string strFileName = filetomerge.Substring(filetomerge.LastIndexOf(Path.DirectorySeparatorChar)

  • C#文件分割的方法

    本文实例讲述了C#文件分割的方法.分享给大家供大家参考.具体如下: 1. 小文件分割(适用于小于等于64M的文件): using System; using System.IO; string filetosplit=@"C:\temp\data.bin"; string targetpath=@"D:\store"; FileStream fsr = new FileStream(filetosplit, FileMode.Open, FileAccess.Rea

  • C#自适应合并文件的方法

    本文实例讲述了C#自适应合并文件的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.IO; namespace MergeFile { class Program { public static void Main(string[] args) { int count=1; string sourcepath=@"D:\SplitFile"; string filetomerge=@"C:\编程的奥秘.pdf";

  • Python实现分割文件及合并文件的方法

    本文实例讲述了Python实现分割文件及合并文件的方法.分享给大家供大家参考.具体如下: 分割文件split.py如下: #!/usr/bin/python ########################################################################## # split a file into a set of parts; join.py puts them back together; # this is a customizable ve

  • PHP实现断点续传乱序合并文件的方法

    本文实例讲述了PHP实现断点续传乱序合并文件的方法.分享给大家供大家参考,具体如下: 分割成多个文件发送,由于网络原因并不上先发就能发接收到.所以我们不能按顺序合并. 分割文件源码前面一篇文章<PHP断点续传之文件分割合并> merge2.php <?php $fileTotaiSize = filesize("socket.zip"); $filelist = glob('./split/*socket*.tmp'); $filesize = 3096; //打乱读

  • Python实现合并同一个文件夹下所有txt文件的方法示例

    本文实例讲述了Python实现合并同一个文件夹下所有txt文件的方法.分享给大家供大家参考,具体如下: 一.需求分析 合并一个文件夹下所有txt文件 二.合并效果 三.python实现代码 # -*- coding:utf-8*- import sys reload(sys) sys.setdefaultencoding('utf-8') import os import os.path import time time1=time.time() ########################

  • 使用grunt合并压缩js和css文件的方法

    需要了解的知识: 1.nodejs的安装与命令行使用 2.nodejs安装应用 3.grunt的初步了解 本文已假定读者已经熟悉以上知识. 好,我们继续: 任务1:将src目录下的所有zepto及插件合并,并压缩. --src/ ajax.js assets.js callbacks.js data.js deferred.js detect.js event.js form.js fx.js fx_methods.js gesture.js ie.js ios3.js selector.js

  • PHP实现将多个文件中的内容合并为新文件的方法示例

    本文实例讲述了PHP实现将多个文件中的内容合并为新文件的方法.分享给大家供大家参考,具体如下: function test() { $hostdir= iconv("utf-8","gbk","C:\Users\原万里\Desktop\日常笔记") ; //iconv()转换编码方式,将UTF-8转换为gbk,若是报错在gbk后加//IGNORE $filesnames = scandir($hostdir); //scandir() 函数返回指

  • Python实现将目录中TXT合并成一个大TXT文件的方法

    本文实例讲述了Python实现将目录中TXT合并成一个大TXT文件的方法.分享给大家供大家参考.具体如下: 在网上下了一个dota的英雄攻略,TXT格式,每个英雄一个文件,看得疼,就写了一个小东西,合并一下. #coding=gbk import os import sys import glob def dirTxtToLargeTxt(dir,outputFileName): '''从dir目录下读入所有的TXT文件,将它们写到outputFileName里去''' #如果dir不是目录返回

  • Linux下文件的切分与合并的简单方法介绍

    linux下文件分割可以通过split命令来实现,可以将一个大文件拆分成指定大小的多个文件,并且拆分速度非常的快,可以指定按行数分割和安大小分割两种模式.Linux下文件合并可以通过cat命令来实现,非常简单. 在Linux下用split进行文件分割 先看下帮助文档 Usage: split [OPTION]... [INPUT [PREFIX]] Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size

  • node下使用UglifyJS压缩合并JS文件的方法

    现在UglifyJS的最新版本为 2.8.13,主要功能为JS的压缩和合并,下面直接进入教程: 安装: <span style="font-size:18px;color:#006600;">npm install uglify-js -g</span> 将uglifyjs安装为全局变量,方便我们在任何地方使用. <span style="color:#006600;">下面是shell命令的中文解释: * source-map

  • python:pandas合并csv文件的方法(图书数据集成)

    数据集成:将不同表的数据通过主键进行连接起来,方便对数据进行整体的分析. 两张表:ReaderInformation.csv,ReaderRentRecode.csv ReaderInformation.csv: ReaderRentRecode.csv: pandas读取csv文件,并进行csv文件合并处理: # -*- coding:utf-8 -*- import csv as csv import numpy as np # ------------- # csv读取表格数据 # ---

随机推荐