java文件的拆分与合并Word格式文档下载.docx

上传人:b****5 文档编号:17080314 上传时间:2022-11-28 格式:DOCX 页数:9 大小:17.86KB
下载 相关 举报
java文件的拆分与合并Word格式文档下载.docx_第1页
第1页 / 共9页
java文件的拆分与合并Word格式文档下载.docx_第2页
第2页 / 共9页
java文件的拆分与合并Word格式文档下载.docx_第3页
第3页 / 共9页
java文件的拆分与合并Word格式文档下载.docx_第4页
第4页 / 共9页
java文件的拆分与合并Word格式文档下载.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

java文件的拆分与合并Word格式文档下载.docx

《java文件的拆分与合并Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《java文件的拆分与合并Word格式文档下载.docx(9页珍藏版)》请在冰豆网上搜索。

java文件的拆分与合并Word格式文档下载.docx

;

JLabelsplitSourceSize,coalitionTotalSize,coalitionTotalCount;

JTextFieldSplitSource,SplitTotalCount,SplitEachSize,coalitionSource;

//*****************************************申明结束

publicApplication1(){

super("

工具"

);

this.setSize(640,480);

this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);

JPanelcontentPanel=(JPanel)this.getContentPane();

contentPanel.setLayout(newBorderLayout());

JTabbedPanejtp=newJTabbedPane();

jtp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

JPanelsplitPane=newJPanel(newGridLayout(5,1));

JPanelsplitPane0=newJPanel(newBorderLayout());

splitPane0.add(splitPane,BorderLayout.NORTH);

JPanelsplitPane1=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelsplitPane2=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelsplitPane3=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelsplitPane4=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelsplitPane5=newJPanel();

splitPane1.add(newJLabel("

拆分源文件:

));

SplitSource=newJTextField(40);

splitPane1.add(SplitSource);

JButtonSplitJButton=newJButton("

浏览..."

SplitJButton.addActionListener(newActionListener(){

 

publicvoidactionPerformed(ActionEvente){

SplitJButtonClick(e);

//选择要拆分的文件

}

});

splitPane1.add(SplitJButton);

splitSourceSize=newJLabel("

源文件大小:

splitPane2.add(splitSourceSize);

splitPane3.add(newJLabel("

拆分的数目:

SplitTotalCount=newJTextField(15);

SplitTotalCount.setDocument(newNumberDocument());

//限制输入框只能输入数字

SplitTotalCount.getDocument().addDocumentListener(newDocumentListener(){//给输入框添加事件

publicvoidchangedUpdate(DocumentEvente){

if(!

Application1.this.SplitTotalCount.isFocusOwner())return;

try{SplitTotalCount_changedUpdate(e);

}catch(Exceptionex){System.err.println(ex.toString());

}

publicvoidinsertUpdate(DocumentEvente){

publicvoidremoveUpdate(DocumentEvente){

splitPane3.add(SplitTotalCount);

splitPane4.add(newJLabel("

单文件大小:

SplitEachSize=newJTextField(15);

SplitEachSize.setDocument(newNumberDocument());

SplitEachSize.getDocument().addDocumentListener(newDocumentListener(){//给输入框添加事件

Application1.this.SplitEachSize.isFocusOwner())return;

try{SplitEachSize_changedUpdate(e);

splitPane4.add(SplitEachSize);

JButtonSplitJB=newJButton("

开始拆分"

SplitJB.addActionListener(newActionListener(){

try{SplitJBClick(e);

}//<

ahref="

keyword=拆分文件"

拆分文件<

splitPane5.add(SplitJB);

splitPane.add(splitPane1);

splitPane.add(splitPane2);

splitPane.add(splitPane3);

splitPane.add(splitPane4);

splitPane.add(splitPane5);

JPanelcoalitionPane0=newJPanel(newBorderLayout());

JPanelcoalitionPane=newJPanel(newGridLayout(4,1));

coalitionPane0.add(coalitionPane,BorderLayout.NORTH);

JPanelcoalitionPane1=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelcoalitionPane2=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelcoalitionPane3=newJPanel(newFlowLayout(FlowLayout.LEADING));

JPanelcoalitionPane4=newJPanel();

coalitionPane1.add(newJLabel("

合并首文件:

coalitionSource=newJTextField(40);

coalitionPane1.add(coalitionSource);

JButtoncoalitionJButton=newJButton("

浏览(*.000)"

coalitionJButton.addActionListener(newActionListener(){

coalitionJButtonClick(e);

//选择要合并的首文件

coalitionPane1.add(coalitionJButton);

coalitionPane.add(coalitionPane1);

coalitionTotalSize=newJLabel("

文件总大小:

coalitionPane2.add(coalitionTotalSize);

coalitionPane.add(coalitionPane2);

coalitionTotalCount=newJLabel("

文件总数目:

coalitionPane3.add(coalitionTotalCount);

coalitionPane.add(coalitionPane3);

JButtoncoalitionJB=newJButton("

开始合并"

coalitionJB.addActionListener(newActionListener(){

try{coalitionJBClick(e);

keyword=合并文件"

合并文件<

coalitionPane4.add(coalitionJB);

coalitionPane.add(coalitionPane4);

jtp.add("

splitPane0);

coalitionPane0);

contentPanel.add(jtp,BorderLayout.CENTER);

this.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){

System.exit(0);

//当关闭窗口时退出系统

this.setVisible(true);

//********************************************以上为图形界面设计

}

privatevoidSplitJBClick(ActionEvente)throwsException{//<

操作

Filefile=newFile(this.SplitSource.getText());

file.exists()){

JOptionPane.showMessageDialog(this,"

源文件不存在!

"

警告"

JOptionPane.WARNING_MESSAGE);

return;

javax.swing.JFileChooserfjc;

fjc=newjavax.swing.JFileChooser(filepath);

fjc.removeChoosableFileFilter(fjc.getAcceptAllFileFilter());

fjc.setDialogTitle("

选择保存目录"

fjc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

if(fjc.APPROVE_OPTION!

=fjc.showOpenDialog(this))return;

filepath=fjc.getSelectedFile().getPath();

byte[]b=newbyte[1024];

intread=0;

Stringsplitfilename=file.getName();

inteachfilesize=Integer.parseInt(this.SplitEachSize.getText());

FileInputStreamfis=newFileInputStream(file);

FileOutputStreamfos;

Stringsavesplitfilename="

for(longsplitcount=0;

splitcount<

Long.parseLong(this.SplitTotalCount.getText());

splitcount++){

savesplitfilename=fjc.getSelectedFile()+"

/"

+splitfilename+"

.xiruo."

if(String.valueOf(splitcount).length()==1)

savesplitfilename+="

00"

+splitcount;

elseif(String.valueOf(splitcount).length()==2)

0"

else

savesplitfilename+=splitcount;

fos=newFileOutputStream(savesplitfilename);

inteachread=b.length;

inthasread=0;

while((read=fis.read(b,0,eachread))>

0){

fos.write(b,0,read);

fos.flush();

hasread+=read;

if(hasread>

=eachfilesize&

&

splitcount!

=Long.parseLong(this.SplitTotalCount.getText())-1)

break;

if(eachfilesize-hasread<

(long)b.length)

eachread=eachfilesize-hasread;

fos.close();

fos=null;

拆分完成"

privatevoidcoalitionJBClick(ActionEvente)throwsException{//<

Filefile=newFile(this.coalitionSource.getText());

Stringselfilename=file.getName();

selfilename=selfilename.substring(0,selfilename.lastIndexOf("

."

Stringsavefile=fjc.getSelectedFile().getAbsolutePath()+"

+selfilename.substring(0,selfilename.lastIndexOf("

if(newFile(savefile).exists()){

intjavaok=JOptionPane.showConfirmDialog(this,"

文件名"

+newFile(savefile).getName()+"

的文件已经存在,你要覆盖原来的文件吗?

警告!

JOptionPane.OK_CANCEL_OPTION);

if(javaok==JOptionPane.CANCEL_OPTION)return;

FileOutputStreamfos=newFileOutputStream(savefile);

FileInputStreamfis;

File[]f=file.getParentFile().listFiles();

for(inti=0;

i<

f.length;

i++){

f[i].getName().startsWith(selfilename))continue;

fis=newFileInputStream(f[i]);

while((read=fis.read(b,0,b.length))>

fos.write(b,0,read);

fis.close();

fis=null;

合并完成"

privatevoidSplitTotalCount_changedUpdate(DocumentEvente)throwsException{

file.exists()||this.SplitTotalCount.getText().equals("

))return;

longl=Long.parseLong(this.SplitTotalCount.getText());

if(l<

=0)return;

this.SplitEachSize.setText(String.valueOf(file.length()/l));

privatevoidSplitEachSize_changedUpdate(DocumentEvente)throwsException{

file.exists()||this.SplitEachSize.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1