谁知道 文件分割合并工具的 C++源码啊?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谁知道 文件分割合并工具的 C++源码啊?相关的知识,希望对你有一定的参考价值。

实现基本功能就行

给你个Java的
public class FileCut
/*cl_tl*/

private Shell shell;
private Display display;
private Text txtSourceFile;
private Text txtNewFilePath;
private Text txtFileSize;
private Button btnChooseFile;
private Button btnChoosePath;
private Button btnCut;
private Button btnUnionFiles;
private Button btnUp;
private Button btnDown;
private Button btnClear;
private Button btnClearAll;
private Button btnUnion;
private Table tblFileList;

private File sourceFile = null; /*源文件*/
private File[] newFile = null; /*分割后产生的文件*/
private int fileCount = 0; /*分割成的文件个数*/
private int fileSize = 0; /*分割的文件块大小*/
private String strSourceFile = null; /*源文件路径及名称*/
private String strNewFilePath = null; /*分割文件存放路径*/

public static void main(String[] args)

Display display=new Display();
FileCut Item=new FileCut();
Item.createShell();

while( !Item.shell.isDisposed())

if(!display.readAndDispatch())
display.sleep();

display.dispose();


/*fn_hd
*rem:创建窗体
*aut:
*log:2005-11-24
*/
private void createShell()
/*fn_tl*/

shell = new Shell(display, SWT.MIN);
shell.setBounds(300,250,500,330);
shell.setText("文件分割合并");
GridLayout shellLayout = new GridLayout();
shellLayout.numColumns = 3;
shell.setLayout(shellLayout);
createWidgets();
shell.open();


/**fn_hd
*rem:在窗体内添加控件
*per:
*aut:
*log:2005-11-24
*/
private void createWidgets()
/*fn_tl*/

final Label lblNull0 = new Label(shell,SWT.None);
GridData gd0 = new GridData();
gd0.horizontalSpan = 3;
lblNull0.setLayoutData(gd0);

final Label lblSourceFile = new Label(shell, SWT.None);
lblSourceFile.setText("源 文 件");

GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
txtSourceFile = new Text(shell, SWT.BORDER);
txtSourceFile.setLayoutData(gd2);

btnChooseFile = new Button(shell, SWT.PUSH);
btnChooseFile.setText("..");

final Label lblPath = new Label(shell, SWT.None);
lblPath.setText("存放路径");

txtNewFilePath = new Text(shell, SWT.BORDER);
GridData gd3 = new GridData(GridData.FILL_HORIZONTAL);
txtNewFilePath.setLayoutData(gd3);

btnChoosePath = new Button(shell, SWT.PUSH);
btnChoosePath.setText("..");

final Label lblSize = new Label(shell, SWT.None);
lblSize.setText("分块大小(KB)");

txtFileSize = new Text(shell,SWT.BORDER);
GridData gd7 = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
txtFileSize.setLayoutData(gd7);

btnCut = new Button(shell, SWT.PUSH);
GridData gd4 = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
btnCut.setLayoutData(gd4);
btnCut.setText("开始分割");

final Label lbl1 = new Label(shell, SWT.None);
GridData gd8 = new GridData();
gd8.horizontalSpan = 3;
lbl1.setLayoutData(gd8);
lbl1.setText("待合并的文件列表");

tblFileList = new Table(shell, SWT.BORDER);
GridData gd1 = new GridData(GridData.FILL_BOTH);
gd1.horizontalSpan = 2;
tblFileList.setLayoutData(gd1);

Composite com = new Composite(shell, SWT.None);
GridLayout comLayout = new GridLayout();
com.setLayout(comLayout);

final Label lblNote = new Label(shell, SWT.None);
GridData data = new GridData();
data.horizontalSpan=3;
lblNote.setLayoutData(data);
lblNote.setText("提示:注意合并文件的顺序");

btnUnionFiles = new Button(com, SWT.PUSH);
btnUnionFiles.setText("选择文件");

btnUp = new Button(com, SWT.PUSH);
btnUp.setText(" 上移 ");
btnUp.setEnabled(false);

btnDown = new Button(com, SWT.PUSH);
btnDown.setText(" 下移 ");
btnDown.setEnabled(false);

btnClear = new Button(com, SWT.PUSH);
btnClear.setText(" 删除 ");
btnClear.setEnabled(false);

btnClearAll = new Button(com, SWT.PUSH);
btnClearAll.setText("清空列表");

btnUnion = new Button(com, SWT.PUSH);
btnUnion.setText("开始合并");

btnCut.addSelectionListener(new SelectionAdapter()
//添加"开始分割"监视器

public void widgetSelected(SelectionEvent event)

cutButtonEvent();

);

btnChooseFile.addSelectionListener(new SelectionAdapter()
//添加选择(源文件)监视器

public void widgetSelected(SelectionEvent event)

FileDialog fdOpen = new FileDialog(shell,SWT.OPEN);
String strFileName = fdOpen.open();
if (strFileName != null)

txtSourceFile.setText(strFileName);
txtNewFilePath.setText(fdOpen.getFilterPath());
txtFileSize.setFocus();


);

btnChoosePath.addSelectionListener(new SelectionAdapter()
//添加选择(分割文件存放路径)监视器

public void widgetSelected(SelectionEvent event)

DirectoryDialog dirDia = new DirectoryDialog(shell);
String strFileDir = dirDia.open();
if (strFileDir != null)

txtNewFilePath.setText(strFileDir);
txtFileSize.setFocus();


);

btnUp.addSelectionListener(new SelectionAdapter()
//添加"上移"监视器

public void widgetSelected(SelectionEvent event)

//int[] itemIndices = tblFileList.getSelectionIndices();
int itemIndex = tblFileList.getSelectionIndex();
if (itemIndex == 0)

tblFileList.setFocus();
return;

//交换列表中两行的内容
String strTemp = tblFileList.getItem(itemIndex).getText();
tblFileList.getItem(itemIndex).setText(tblFileList.getItem(
itemIndex - 1).getText());
tblFileList.getItem(itemIndex - 1).setText(strTemp);
//设置焦点
tblFileList.setSelection(itemIndex - 1);
tblFileList.setFocus();

);

btnDown.addSelectionListener(new SelectionAdapter()
//添加"下移"监视器

public void widgetSelected(SelectionEvent event)

//int[] itemIndices = tblFileList.getSelectionIndices();
int itemIndex = tblFileList.getSelectionIndex();
if (itemIndex == tblFileList.getItemCount() - 1)

tblFileList.setFocus();
return;

//交换列表中两行的内容
String strTemp = tblFileList.getItem(itemIndex).getText();
tblFileList.getItem(itemIndex).setText(tblFileList.getItem(
itemIndex + 1).getText());
tblFileList.getItem(itemIndex + 1).setText(strTemp);
//设置焦点
tblFileList.setSelection(itemIndex + 1);
tblFileList.setFocus();

);

btnClear.addSelectionListener(new SelectionAdapter()
//添加"删除"监视器

public void widgetSelected(SelectionEvent event)

int itemIndex = tblFileList.getSelectionIndex();
tblFileList.remove(itemIndex);
btnUp.setEnabled(false);
btnDown.setEnabled(false);
btnClear.setEnabled(false);

);

btnClearAll.addSelectionListener(new SelectionAdapter()
//添加"清空列表"监视器

public void widgetSelected(SelectionEvent event)

tblFileList.removeAll();
btnUp.setEnabled(false);
btnDown.setEnabled(false);
btnClear.setEnabled(false);

);

txtFileSize.addSelectionListener(new SelectionAdapter()
//添加"分块大小"文本框中输入回车监视器

public void widgetDefaultSelected(SelectionEvent event)

cutButtonEvent();

);

btnUnionFiles.addSelectionListener(new SelectionAdapter()
//添加"选择文件"监视器

public void widgetSelected(SelectionEvent event)

FileDialog fd = new FileDialog(shell, SWT.MULTI);
fd.setFilterExtensions(new String[]"*.dat", "*.*");
if (fd.open() != null)

String[] strFiles = fd.getFileNames();
String strFilePath = fd.getFilterPath();
//strUnionFilePath = new String[strFiles.length];
for(int i = 0; i < strFiles.length; i++)

//strUnionFilePath[i] = fd.getFilterPath();
TableItem item = new TableItem(tblFileList, SWT.None);
item.setText(strFilePath + "\\" + strFiles[i]);



);

btnUnion.addSelectionListener(new SelectionAdapter()
//添加"开始合并"监视器

public void widgetSelected(SelectionEvent event)

if (tblFileList.getItemCount() == 0)

return;

switch (unionFiles())

case 1:
showMessage("成功", "合并完成!",
SWT.OK | SWT.ICON_INFORMATION);
tblFileList.removeAll();
btnUp.setEnabled(false);
btnDown.setEnabled(false);
btnClear.setEnabled(false);
break;
case -1:
showMessage("错误", "文件不存在!",
SWT.OK | SWT.ICON_ERROR);
break;
case -2:
break;
default:
showMessage("错误", "有错误发生,文件合并失败!",
SWT.OK | SWT.ICON_ERROR);


);

tblFileList.addSelectionListener(new SelectionAdapter()
//添加选中列表中元素监视器

public void widgetSelected(SelectionEvent event)

btnUp.setEnabled(true);
btnDown.setEnabled(true);
btnClear.setEnabled(true);

);


/**fn_hd
*rem:显示消息框
*log:2005-11-24
*/
private int showMessage(String strText, String strMessage, int i)
/*fn_tl*/
MessageBox msgBox = new MessageBox(shell,i);
msgBox.setText(strText);
msgBox.setMessage(strMessage);
return msgBox.open();


/**fn_hd
*rem:点击"分割"按钮触发的事件响应
*log:2005-11-24
*/
private void cutButtonEvent()
/*fn_tl*/

strSourceFile = txtSourceFile.getText().trim();
strNewFilePath = txtNewFilePath.getText().trim();

if (strSourceFile.equals("") || strNewFilePath.equals(""))

showMessage("提示", "请输入源文件和 \n\n分割文件的路径! ",
SWT.OK | SWT.ICON_INFORMATION);
return;

try

fileSize = Integer.parseInt(txtFileSize.getText());
fileSize *= 1024;
if (fileSize <= 0)

showMessage("错误", "分块大小为正整数! ",
SWT.OK | SWT.ICON_ERROR);
return;


catch(Exception e)

showMessage("错误", "请在分块大小框填入数字! ",
SWT.OK | SWT.ICON_ERROR);
return;

switch (cutFile())

case 1:
showMessage("提示", "分割完成! ", SWT.OK |
SWT.ICON_INFORMATION);
txtSourceFile.setText("");
txtNewFilePath.setText("");
txtFileSize.setText("");
break;
case -1:
showMessage("错误", "源文件不存在或存放路径不存在!",
SWT.OK | SWT.ICON_ERROR);
break;
default:
showMessage("未知错误", "文件分割失败! ",
SWT.OK | SWT.ICON_ERROR);



/*fn_hd
*rem:文件分割实现
*per:成功返回1,文件未找到返回-1,其他情况返回0
*exp:IOException
*aut:
*log:2005-11-22,创建
*log:2005-11-24,修改
*/
private int cutFile()
/*fn_tl*/

sourceFile = new File(strSourceFile);
fileCount = (int) (sourceFile.length() / fileSize);
if (sourceFile.length() % fileSize != 0)

fileCount++;

newFile = new File[fileCount];

try

int count = 0;
int i = 0;
byte[] bueff = new byte[fileSize];
FileOutputStream out = null;
FileInputStream in = new FileInputStream(sourceFile);
for (i = 0; i < newFile.length; i++)

newFile[i] = new File(strNewFilePath,
i + sourceFile.getName() + ".dat");

i = 0;
while ((count = in.read(bueff,0,fileSize)) != -1)

out = new FileOutputStream(newFile[i]);
out.write(bueff,0,count);
out.close();
i++;

in.close();
return 1;

catch(FileNotFoundException e)

System.out.println(e);
return -1;

catch(IOException e)

System.out.println(e);
return 0;



/*fn_hd
*rem:文件合并的实现
*per:成功返回1,文件未找到返回-1,取消操作返回-2,其他情况返回0;
*aut:
*exp:FileNotFoundException,IOException
*log:2005-11-28,创建
*/
private int unionFiles()
/*fn_tl*/

String[] strFiles = new String[tblFileList.getItemCount()];
File[] unionFiles = new File[strFiles.length];
FileDialog fdSave = new FileDialog(shell, SWT.SAVE);
String s = fdSave.open();
if (s == null)

return -2;

File outFile = new File(fdSave.getFilterPath(),
fdSave.getFileName());
if (outFile.exists())

int msg = showMessage("提示", "该文件以存在,是否替换?",
SWT.YES | SWT.NO | SWT.ICON_QUESTION);
if (msg == SWT.NO)

return -2;


for(int i = 0; i < strFiles.length; i++)

strFiles[i] = tblFileList.getItem(i).getText();

try

FileInputStream in = null;
FileOutputStream out = new FileOutputStream(outFile);
byte[] buff = new byte[1024];
int count;
for(int i = 0; i < strFiles.length; i++)

in = new FileInputStream(strFiles[i]);
while((count = in.read(buff,0,1024)) != -1)

out.write(buff,0,count);

in.close();

out.close();
return 1;

catch(FileNotFoundException e)

System.out.println(e);
return -1;

catch(IOException e)

System.out.println(e);
return 0;



参考技术A 是用标准C++实现还是可以利用Framework?
基本原理就是读到文件流里,再一块一块读出写到新文件里。
我这里有一份BCB的源码,翻译成标准C++或VC的CFile实现也不难,需要的话说一声即可
参考技术B 分割就行了?

不要压缩?
参考技术C winRAR就行 别告诉我你不知道这个软件~

谁知道这一步怎么操作啊?jira 5.2.10版本的,不胜感激!

参考技术A 你是要现在捆绑一个数据库还是稍后连接到自己的数据库追问

那应该怎么操作啊

以上是关于谁知道 文件分割合并工具的 C++源码啊?的主要内容,如果未能解决你的问题,请参考以下文章

亲们,谁知道QT中的toolbutton怎么添加小图标呢?资源文件做法不行啊!!就整成这样的:

谁知道在linux下的常用后缀名啊?

body的默认CSS属性谁知道啊

谁知道DOS的一些基本的命令啊写给我可以吗?

[pdf分割合并工具]PDF分割合并工具免费版|PDF分割合并工具 V1.0 绿色免费版 下载

请问谁知道在Ai中怎么将zoom工具改成鼠标滑动快捷键