java文件的拆分与合并Word格式文档下载.docx
- 文档编号:17080314
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:9
- 大小:17.86KB
java文件的拆分与合并Word格式文档下载.docx
《java文件的拆分与合并Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《java文件的拆分与合并Word格式文档下载.docx(9页珍藏版)》请在冰豆网上搜索。
;
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.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 文件 拆分 合并
![提示](https://static.bdocx.com/images/bang_tan.gif)