C#版文件分割器
直接上图,接着上一篇的文本分割器,实验要求如下:
1. 能进行文件分割
2. 分割块大小由用户输入决定
3. 能进行文件合并
4. 文件分割与合并过程用线程来实现
5. 数据缓冲区不得超过2K
6. 要有处理进度显示
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class 文件分割器1 : Form
{
//时间:2012-9-6
//作者:Olive
//功能:实现大文件的分割、合并
#region Members
int count1,count,fgkDaXiao;
FileInfo fFenGe,fHeBing;
FileStream fStream,hStream;
string fenGeLuJing,heBingLuJing;
int value = 0;
#endregion
#region Methods
public 文件分割器1()
{
InitializeComponent();
skinEngine1.SkinFile = "WarmColor1.ssk";
}
/// <summary>
/// 选择要分割的文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnfgwenjian_Click(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fFenGe = new FileInfo(openFileDialog1.FileName);
txtfenge.Text = fFenGe.FullName;
fenGeLuJing = fFenGe.FullName.Substring(0, fFenGe.FullName.Length - openFileDialog1.SafeFileName.Length);
txtwjdaxiao.Text = ((int)fFenGe.Length/1024).ToString();
fStream = new FileStream(fFenGe.FullName, FileMode.Open, FileAccess.Read);
}
}
catch
{
MessageBox.Show("文件分割异常,请检查确认无误后再次分割!");
}
}
/// <summary>
/// 选择要保存的路径,如果不选默认为与原文件同路径
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnfglujing_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtfgkdaxiao.Text))
{
MessageBox.Show("请输入文件分割块大小!");
}
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
txtfglujing.Text= folderBrowserDialog1.SelectedPath;
fenGeLuJing = folderBrowserDialog1.SelectedPath+"\\";
}
}
/// <summary>
/// 分割文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnfenge_Click(object sender, EventArgs e)
{
try
{
int wenJianLength = Convert.ToInt32(txtwjdaxiao.Text);
if (wenJianLength % fgkDaXiao == 0)
{
count = wenJianLength / fgkDaXiao;
}
else
{
count = wenJianLength / fgkDaXiao + 1;
}
&
补充:软件开发 , C# ,