1、;JLabel splitSourceSize,coalitionTotalSize,coalitionTotalCount;JTextField SplitSource,SplitTotalCount,SplitEachSize,coalitionSource;/*申明结束public Application1() super(工具);this.setSize(640,480);this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize
2、().height/2-this.getHeight()/2);JPanel contentPanel=(JPanel)this.getContentPane();contentPanel.setLayout(new BorderLayout();JTabbedPane jtp=new JTabbedPane();jtp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);JPanel splitPane=new JPanel(new GridLayout(5,1);JPanel splitPane0=new JPanel(new BorderL
3、ayout();splitPane0.add(splitPane,BorderLayout.NORTH);JPanel splitPane1=new JPanel(new FlowLayout(FlowLayout.LEADING);JPanel splitPane2=new JPanel(new FlowLayout(FlowLayout.LEADING);JPanel splitPane3=new JPanel(new FlowLayout(FlowLayout.LEADING);JPanel splitPane4=new JPanel(new FlowLayout(FlowLayout.
4、LEADING);JPanel splitPane5=new JPanel();splitPane1.add(new JLabel(拆分源文件:);SplitSource=new JTextField(40);splitPane1.add(SplitSource);JButton SplitJButton=new JButton(浏览.SplitJButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) SplitJButtonClick(e);/选择要拆分的文件 );spl
5、itPane1.add(SplitJButton);splitSourceSize=new JLabel(源文件大小:splitPane2.add(splitSourceSize);splitPane3.add(new JLabel(拆分的数目:SplitTotalCount=new JTextField(15);SplitTotalCount.setDocument(new NumberDocument();/限制输入框只能输入数字SplitTotalCount.getDocument().addDocumentListener(new DocumentListener() /给输入框添加事
6、件 public void changedUpdate(DocumentEvent e) if(!Application1.this.SplitTotalCount.isFocusOwner()return; trySplitTotalCount_changedUpdate(e);catch(Exception ex)System.err.println(ex.toString(); public void insertUpdate(DocumentEvent e) public void removeUpdate(DocumentEvent e) splitPane3.add(SplitTo
7、talCount);splitPane4.add(new JLabel(单文件大小:SplitEachSize=new JTextField(15);SplitEachSize.setDocument(new NumberDocument();SplitEachSize.getDocument().addDocumentListener(new DocumentListener() /给输入框添加事件Application1.this.SplitEachSize.isFocusOwner()return; trySplitEachSize_changedUpdate(e);splitPane4
8、.add(SplitEachSize);JButton SplitJB=new JButton(开始拆分SplitJB.addActionListener(new ActionListener() trySplitJBClick(e);/a href=keyword=拆分文件拆分文件splitPane5.add(SplitJB);splitPane.add(splitPane1);splitPane.add(splitPane2);splitPane.add(splitPane3);splitPane.add(splitPane4);splitPane.add(splitPane5);JPan
9、el coalitionPane0=new JPanel(new BorderLayout();JPanel coalitionPane=new JPanel(new GridLayout(4,1);coalitionPane0.add(coalitionPane,BorderLayout.NORTH);JPanel coalitionPane1=new JPanel(new FlowLayout(FlowLayout.LEADING);JPanel coalitionPane2=new JPanel(new FlowLayout(FlowLayout.LEADING);JPanel coal
10、itionPane3=new JPanel(new FlowLayout(FlowLayout.LEADING);JPanel coalitionPane4=new JPanel();coalitionPane1.add(new JLabel(合并首文件:coalitionSource=new JTextField(40);coalitionPane1.add(coalitionSource);JButton coalitionJButton=new JButton(浏览(*.000)coalitionJButton.addActionListener(new ActionListener()
11、 coalitionJButtonClick(e);/选择要合并的首文件coalitionPane1.add(coalitionJButton);coalitionPane.add(coalitionPane1);coalitionTotalSize=new JLabel(文件总大小:coalitionPane2.add(coalitionTotalSize);coalitionPane.add(coalitionPane2);coalitionTotalCount=new JLabel(文件总数目:coalitionPane3.add(coalitionTotalCount);coaliti
12、onPane.add(coalitionPane3);JButton coalitionJB=new JButton(开始合并coalitionJB.addActionListener(new ActionListener() trycoalitionJBClick(e);keyword=合并文件合并文件coalitionPane4.add(coalitionJB);coalitionPane.add(coalitionPane4);jtp.add(,splitPane0);,coalitionPane0);contentPanel.add(jtp,BorderLayout.CENTER);t
13、his.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0);/当关闭窗口时退出系统this.setVisible(true);/*以上为图形界面设计 private void SplitJBClick(ActionEvent e) throws Exception /操作 File file=new File(this.SplitSource.getText();file.exists() JOptionPane.showMessageDialog(this,
14、源文件不存在!,警告,JOptionPane.WARNING_MESSAGE); return; javax.swing.JFileChooser fjc; fjc=new javax.swing.JFileChooser(filepath); fjc.removeChoosableFileFilter(fjc.getAcceptAllFileFilter(); fjc.setDialogTitle(选择保存目录 fjc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if(fjc.APPROVE_OPTION!=fjc.showOpe
15、nDialog(this)return; filepath=fjc.getSelectedFile().getPath(); byte b=new byte1024; int read=0; String splitfilename=file.getName(); int eachfilesize=Integer.parseInt(this.SplitEachSize.getText(); FileInputStream fis=new FileInputStream(file); FileOutputStream fos; String savesplitfilename= for(long
16、 splitcount=0;splitcount0) 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;拆分完成private void coalitionJBClick(Action
17、Event e) throws Exception / File file=new File(this.coalitionSource.getText(); String selfilename=file.getName(); selfilename=selfilename.substring(0,selfilename.lastIndexOf(. String savefile=fjc.getSelectedFile().getAbsolutePath()+selfilename.substring(0,selfilename.lastIndexOf( if(new File(savefil
18、e).exists() int javaok=JOptionPane.showConfirmDialog(this,文件名 +new File(savefile).getName()+ 的文件已经存在,你要覆盖原来的文件吗?警告!,JOptionPane.OK_CANCEL_OPTION); if(javaok=JOptionPane.CANCEL_OPTION)return; FileOutputStream fos=new FileOutputStream(savefile); FileInputStream fis; File f=file.getParentFile().listFil
19、es(); for(int i=0;i fos.write(b, 0, read); fis.close(); fis=null;合并完成private void SplitTotalCount_changedUpdate(DocumentEvent e) throws Exception file.exists()|this.SplitTotalCount.getText().equals()return; long l=Long.parseLong(this.SplitTotalCount.getText(); if(l=0)return; this.SplitEachSize.setText(String.valueOf(file.length()/l);private void SplitEachSize_changedUpdate(DocumentEvent e) throws Exception file.exists()|this.SplitEachSize.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1