以下是源码:


import java.awt.Panel; import java.awt.TextField; import java.awt.Frame; import java.awt.Button; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import javax.swing.JLabel; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.ButtonGroup; import javax.swing.JFileChooser; import javax.swing.border.TitledBorder; import java.awt.event.ActionListener; import javax.swing.JSplitPane; import javax.swing.UIManager; import javax.swing.JOptionPane; import javax.swing.Box; import javax.swing.JFrame; import java.io.File; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.BufferedOutputStream; import java.io.FileOutputStream; public class SplitFiles extends JFrame implements ActionListener { private JTextField showSourcePath=new JTextField(); private JTextField showDestinationPath=new JTextField(); private JButton source=new JButton("源文件"); private JButton destination=new JButton("目标文件夹"); private JButton start=new JButton("确定"); private JRadioButton splitByAvg=new JRadioButton("平均分割"); private JRadioButton splitBySize=new JRadioButton("指定大小分割"); private JTextField showAvg=new JTextField(); private JLabel showLiang1=new JLabel("分割成?份",JLabel.CENTER); private JTextField showSize=new JTextField(""); private JLabel showLiang2=new JLabel("每份/KB",JLabel.CENTER); private JButton aboutUs=new JButton("关于我们"); private String glz; private JFileChooser fileChooser; private File sourceFile; private File destinationFile; private String destinationPath; private int avgNum; private int sizeNum; public SplitFiles() { ButtonGroup g=new ButtonGroup(); g.add(splitByAvg); g.add(splitBySize); glz="有关于我们的最新情况请访问:www.ourglz.com"+"/n"+"您可以在此讨论任何学习&生活中的事情" +"/n"+"我的邮箱:494763134@qq.com"+"/n"+"我的qq:494763134"+"/n"+"/t"+"---glzlaohuai"+"/n"+"/t"+"2010.4.18"; showSourcePath.setEditable(false); showDestinationPath.setEditable(false); splitByAvg.setSelected(true); showAvg.setEditable(true); showSize.setEditable(false); JPanel p1=new JPanel(); p1.setLayout(new BorderLayout()); p1.add(showSourcePath,BorderLayout.CENTER); JPanel p2=new JPanel(); p2.setLayout(new BorderLayout()); p2.add(showDestinationPath,BorderLayout.CENTER); Box b1=Box.createHorizontalBox(); b1.add(p1); b1.add(Box.createGlue()); b1.add(source); b1.setBorder(new TitledBorder("选择源文件")); Box b2=Box.createHorizontalBox(); b2.add(p2); b2.add(Box.createGlue()); b2.add(destination); b2.setBorder(new TitledBorder("选择目标文件夹")); JPanel p3=new JPanel(); p3.setLayout(new GridLayout(2,1)); p3.add(b1); p3.add(b2); JPanel p9=new JPanel(); p9.setLayout(new FlowLayout()); p9.add(start); JPanel p4=new JPanel(); p4.setLayout(new BorderLayout()); p4.add(p3,BorderLayout.CENTER); p4.add(p9,BorderLayout.SOUTH); p4.setBorder(new TitledBorder("文件选择项")); JPanel p5=new JPanel(); p5.setLayout(new GridLayout(2,1)); p5.add(splitByAvg); p5.add(splitBySize); JPanel p6=new JPanel(); p6.setLayout(new GridLayout(1,2)); p6.add(showAvg); p6.add(showLiang1); p6.setBorder(new TitledBorder("平均分割")); JPanel p7=new JPanel(); p7.setLayout(new GridLayout(1,2)); p7.add(showSize); p7.add(showLiang2); p7.setBorder(new TitledBorder("指定大小分割")); Box b3=Box.createVerticalBox(); b3.add(p6); b3.add(Box.createGlue()); b3.add(p7); JPanel p10=new JPanel(); p10.setLayout(new FlowLayout()); p10.add(aboutUs); JPanel p8=new JPanel(); p8.add(p5,BorderLayout.NORTH); p8.add(b3,BorderLayout.CENTER); p8.add(p10,BorderLayout.SOUTH); p8.setBorder(new TitledBorder("文件分割选项")); JSplitPane splitPanel=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,p4,p8); splitPanel.setDividerLocation(300); aboutUs.addActionListener(this); splitByAvg.addActionListener(this); splitBySize.addActionListener(this); source.addActionListener(this); destination.addActionListener(this); showAvg.addActionListener(this); showSize.addActionListener(this); start.addActionListener(this); this.setLayout(new BorderLayout()); this.add(splitPanel,BorderLayout.CENTER); this.setBounds(300,250,600,200); this.setVisible(true); this.setTitle("文件切割器---created by glzlaohuai"); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String args[]) { try { UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel()); } catch(Exception e) { e.printStackTrace(); } new SplitFiles(); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand()=="关于我们") { JOptionPane.showMessageDialog(this,glz,"GLZ天下游民会",JOptionPane.INFORMATION_MESSAGE,null); } if(e.getActionCommand()=="源文件") { fileChooser=new JFileChooser(); fileChooser.setDialogTitle("请选择源文件"); if(fileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) { sourceFile=fileChooser.getSelectedFile().getAbsoluteFile(); showSourcePath.setText(sourceFile.getAbsolutePath()); } else ; } if(e.getActionCommand()=="目标文件夹") { fileChooser=new JFileChooser(); fileChooser.setDialogTitle("请选择目标文件夹,然后在文件名处输入文件名前缀"); if(fileChooser.showSaveDialog(this)==JFileChooser.APPROVE_OPTION) { destinationFile=fileChooser.getSelectedFile().getAbsoluteFile(); destinationPath=fileChooser.getSelectedFile().getAbsolutePath(); showDestinationPath.setText(destinationPath); System.out.println(destinationPath); } else ; } if(e.getActionCommand()=="平均分割") { showSize.setText(null); showSize.setEditable(false); showAvg.setEditable(true); } if(e.getActionCommand()=="指定大小分割") { showAvg.setText(null); showAvg.setEditable(false); showSize.setEditable(true); } if(e.getActionCommand()=="确定") { if(design()) { split(); } } } public boolean design() { if(!sourceFile.isFile()) { JOptionPane.showMessageDialog(this,"源文件不存在","源文件不存在",JOptionPane.INFORMATION_MESSAGE,null); return false; } if(destinationFile==null) { JOptionPane.showMessageDialog(this,"请选择目标路径","目标路径错误",JOptionPane.INFORMATION_MESSAGE,null); return false; } if(splitByAvg.isSelected()) { try{ avgNum=Integer.parseInt(showAvg.getText().trim()); } catch(Exception e) { JOptionPane.showMessageDialog(this,"请输入平均分割的份数","请输入平均分割的份数",JOptionPane.INFORMATION_MESSAGE,null); return false; } } if(splitBySize.isSelected()) { try { sizeNum=Integer.parseInt(showSize.getText().trim()); } catch(Exception ex) { JOptionPane.showMessageDialog(this,"请输入指定大小","请输入指定大小",JOptionPane.INFORMATION_MESSAGE,null); return false; } } return true; } public void split() { if(splitByAvg.isSelected()) { try{ BufferedInputStream in=new BufferedInputStream(new FileInputStream(sourceFile)); int sourceFileLength=in.available(); int everyFileLength=sourceFileLength/avgNum; int theMod=sourceFileLength%avgNum; int all[]=new int[sourceFileLength]; int every[][]=new int[avgNum-1][everyFileLength]; int lastOne[]=new int[everyFileLength+theMod]; int a=0; int b=0; while((a=in.read())!=-1) { all[b]=a; b++; } a=0; b=0; int c=0; while(a<(avgNum-1)) { while(b<everyFileLength) { every[a][b]=all[c]; c++; b++; } a++; b=0; } a=0; while(c<sourceFileLength) { lastOne[a]=all[c]; c++; a++; } a=0; b=0; while(a<(avgNum-1)) { destinationFile=new File(destinationPath+a+".txt"); try { BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(destinationFile)); while(b<everyFileLength) { out.write(every[a][b]); b++; } a++; b=0; out.close(); } catch(Exception e){ e.printStackTrace(); } } destinationFile=new File(destinationPath+a+".txt"); try{ BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(destinationFile)); while(b<lastOne.length) { out.write(lastOne[b]); b++; } out.close(); } catch(Exception e){ e.printStackTrace(); } } catch(Exception e) { e.printStackTrace(); } JOptionPane.showMessageDialog(this,"分割完毕","分割完毕",JOptionPane.INFORMATION_MESSAGE,null); } if(splitBySize.isSelected()) { try{ BufferedInputStream in=new BufferedInputStream(new FileInputStream(sourceFile)); int sourceFileLength=in.available(); int everyFileLength=sizeNum*1000; int theMod=sourceFileLength%everyFileLength; avgNum=sourceFileLength/everyFileLength; int all[]=new int[sourceFileLength]; int every[][]=new int[avgNum-1][everyFileLength]; int lastOne[]=new int[everyFileLength+theMod]; int a=1; int b=0; while((a=in.read())!=-1) { all[b]=a; b++; } a=0; b=0; int c=0; while(a<(avgNum-1)) { while(b<everyFileLength) { every[a][b]=all[c]; c++; b++; } a++; b=0; } a=0; while(c<sourceFileLength) { lastOne[a]=all[c]; c++; a++; } a=0; b=0; while(a<(avgNum-1)) { destinationFile=new File(destinationPath+a+".txt"); try { BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(destinationFile)); while(b<everyFileLength) { out.write(every[a][b]); b++; } a++; b=0; out.close(); } catch(Exception e){ e.printStackTrace(); } } destinationFile=new File(destinationPath+a+".txt"); try{ BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(destinationFile)); while(b<lastOne.length) { out.write(lastOne[b]); b++; } out.close(); } catch(Exception e){ e.printStackTrace(); } } catch(Exception e) { e.printStackTrace(); } JOptionPane.showMessageDialog(this,"分割完毕","分割完毕",JOptionPane.INFORMATION_MESSAGE,null); } } }

java版文本切割器相关推荐

  1. 使用fastText实现文本分类-java版

    使用FastText实现文本分类-java版 文本分类又称自动文本分类,是指计算机将载有信心的一篇文本映射到预先给定的某一类别或某几个类别主题的过程,实现这一过程的算法模型叫做分类器.哈哈哈,这一句是 ...

  2. java函數_函數(Java版)

    此特性為Java版獨有. 原因:與其他Java版/基岩版特性頁面標題統一 注意: 中文Wiki的移動頁面需要在討論批准後進行,大量移動由機械人完成. 請不要使用複製粘貼來移動頁面,因為這樣會丟失所有的 ...

  3. 我的世界java版移除猪灵了吗_我的世界:激怒僵尸猪灵有奖励,用菌光体堆肥,修复126个漏洞!...

    我的世界Java版1.16pre3(第三个预发布版)已经更新,玩家们从中可以看到一些内容被Mojang调整.首先,下界传送门方块加入战利品表,新增部分常规标签,影响不是很大.按照这样的速度,玩家们等到 ...

  4. 第六篇 :微信公众平台开发实战Java版之如何自定义微信公众号菜单

    我们来了解一下 自定义菜单创建接口: http请求方式:POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/menu/create?access_to ...

  5. 第三篇 :微信公众平台开发实战Java版之请求消息,响应消息以及事件消息类的封装...

    微信服务器和第三方服务器之间究竟是通过什么方式进行对话的? 下面,我们先看下图: 其实我们可以简单的理解: (1)首先,用户向微信服务器发送消息: (2)微信服务器接收到用户的消息处理之后,通过开发者 ...

  6. JAVA我的世界怎么做成就_Editing 成就/Java版

    Anti-spam check. Do not fill this in!{{outdated|成就在[[17w13a]]中被[[进度]]取代.}} [[File:TakingInventory.pn ...

  7. 我的世界java1.13下_Minecraft我的世界Java版1.13-pre3更新内容

    Minecraft我的世界Java版1.13-pre3更新内容!Minecraft 1.13 仍未发布,1.13-pre3 为其第 45 个预览版.本次的更新依旧是众多bug的修复,以及一些优化. 简 ...

  8. GK309协议电子工牌数据模拟器+Socket数据发送 JAVA版-源码

    GK309协议电子工牌数据模拟器+Socket数据发送 JAVA版-源码 说明 源码 EXE执行文件 说明 单JAVA文件,直接运行main方法即可. 只做了GK309的基础位置数据模拟: 0x01 ...

  9. 常见数据结构和算法实现(排序/查找/数组/链表/栈/队列/树/递归/海量数据处理/图/位图/Java版数据结构)

    常见数据结构和算法实现(排序/查找/数组/链表/栈/队列/树/递归/海量数据处理/图/位图/Java版数据结构) 数据结构和算法作为程序员的基本功,一定得稳扎稳打的学习,我们常见的框架底层就是各类数据 ...

最新文章

  1. npm常用命令:ini他、install、remove及编译运行工程、使用淘宝npm镜像
  2. Centos7 安装maven
  3. 初学计算机语言者(C语言,C++,java,pytion,C#)
  4. Razor视图引擎-基础语法
  5. 用unity3d切割图片
  6. Markdown制作表格
  7. python指数积分
  8. css背景图片不显示原因,excel 背景图片(css设置背景图片不显示问题)
  9. mysql置疑原因_SQL SERVER2000数据库置疑处理详解
  10. 用postman GET调试阿里云银行卡二、三、四要素实名认证
  11. 企业综合安防管理平台
  12. 什么是动态页空间?什么静态空间?
  13. 吴伯凡:VUCA时代的自我迭代
  14. hihocoder 博弈三连发
  15. HyperLynx(二十三)DDR(六)DDRx总线批量仿真
  16. 芬兰政府:要找到量子计算工业化的好时机
  17. w8系统桌面没有计算机图标,不见了win8系统桌面图标怎么办
  18. JavaWeb开发技术学习笔记(十四)——集群
  19. 8. 面向对象 -- 继承
  20. 笔试总结——0322联通软笔C++

热门文章

  1. 6. 存储过程:系统存储过程、临时存储过程、本地存储过程
  2. Qt之图形(简笔画-绘制卡通蚂蚁)
  3. 大一新生的pta错题归纳
  4. 关于如何获得虚拟机还是真机信息
  5. OpenStack全网最全部署教程
  6. 读书笔记 | 自动驾驶中的雷达信号处理(第6章 到达方向(DOA)估计算法 )
  7. 粒子群算法实战分享-附原版动画PPT(技术分享也可以文艺范?)
  8. thinkphp6 生成下载动态Excel模板,导出excel文件
  9. Pots --bfs
  10. RFID技术在通道门禁系统的应用