嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
Java文件切割器源代码
public class CutOne extends JFrame implements ActionListener {
public File file;//Add
private JFrame Wnd=null;
LinkFile linkFile;
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenu jMenu2 = new JMenu();
JTabbedPane jTabbedPane1 = new JTabbedPane();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel4 = new JPanel();
JPanel jPanel5 = new JPanel();
JMenu jMenu3 = new JMenu();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem4 = new JMenuItem();
BorderLayout borderLayout2 = new BorderLayout();
JPanel jPanel6 = new JPanel();
JButton jButton4 = new JButton();
BorderLayout borderLayout3 = new BorderLayout();
JPanel jPanel7 = new JPanel();
BorderLayout borderLayout5 = new BorderLayout();
JTextField jTextField1 = new JTextField();
JButton jButton3 = new JButton();
JTextField jTextField2 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
BorderLayout borderLayout4 = new BorderLayout();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JLabel jLabel3 = new JLabel();
JTextField jTextField3 = new JTextField();
BorderLayout borderLayout6 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
BorderLayout borderLayout7 = new BorderLayout();
JScrollPane jScrollPane2 = new JScrollPane();
JTextArea jTextArea2 = new JTextArea();
BorderLayout borderLayout8 = new BorderLayout();
JTextField jTextField4 = new JTextField();
BorderLayout borderLayout10 = new BorderLayout();
JPanel jPanel9 = new JPanel();
BorderLayout borderLayout11 = new BorderLayout();
JPanel jPanel10 = new JPanel();
JLabel jLabel4 = new JLabel();
JButton jButton1 = new JButton();
//Construct the frame
public CutOne() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(CutOne.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setJMenuBar(jMenuBar1);
this.setSize(new Dimension(400, 300));
this.setTitle("CutOne 1.1 wocienyoung");
jMenu1.setText("系 统");
jMenuItem1.setText("退出");
jMenuItem1.addActionListener(this);
jMenu2.setText("联系我");
jPanel1.setFont(new java.awt.Font("Dialog", 0, 14));
jPanel1.setLayout(borderLayout4);
jMenu3.setText("方式");
jMenuItem2.setText("wocienyoung@163.com");
jMenuItem3.setActionCommand("http:// inens.my163.com");
jMenuItem3.setText("http://inens.my163.com");
jMenuItem4.setText("QQ:12527540");
jPanel3.setLayout(borderLayout2);
jButton4.setIcon(new ImageIcon(CutOne.class.getResource("resources/cut.jpg")));
jButton4.setText("开始切割");
jButton4.addActionListener(this);//Cut
jPanel6.setLayout(borderLayout3);
jPanel7.setLayout(borderLayout5);
jButton3.setIcon(new ImageIcon(CutOne.class.getResource("resources/select.jpg")));
jButton3.setText("按此按钮选择");
jButton3.addActionListener(this);//Action
jTextField1.addActionListener(this);
jLabel1.setText("切割后每个文件的大小(Byte):");
jLabel2.setText(" 选 择 文 件 ");
jButton5.setIcon(new ImageIcon(CutOne.class.getResource("resources/select.jpg")));
jButton5.setText("按此按钮选择");
jButton5.addActionListener(this);
jButton6.setIcon(new ImageIcon(CutOne.class.getResource("resources/link.jpg")));
jButton6.setText("开始合并");
jButton6.addActionListener(this);
jLabel3.setText("选择Key文件");
jPanel2.setLayout(borderLayout6);
jTextArea1.setBackground(UIManager.getColor("text"));
jTextArea1.setText("--欢迎你使用CutOne切割工具本程序为你提供Mac Linux Windows...多平台的切割实现。考虑到先前的工具格式,本程序采用了与CofeCut完全兼容的切割算法,并改进了原CofeCut过多的对话式弹出窗口,优化了原来二级窗口停止响应的问题。要运行本程序你必须安装了Java(TM)运行环境,不然您不会看到此界面。使用方法:切割文件请务必填写清楚切割后的文件大小,是以Byte计算的(1024 Byte=1K)不要误添太小造成大量的细小文件产生。如果你有错误报告请联系我--http://inens.my163.com&http://vip.6to23.com/wocienyoung。");
jTextArea1.setLineWrap(true);
jPanel4.setLayout(borderLayout7);
jTextArea2.setBackground(UIManager.getColor("text"));
jTextArea2.setText("CutOne 1.1--版权所有:CofeCut--版权没有:wocienyoung--本程序供广大Java爱好者及需要者学习使用,不得用于谋取利益,更改本程序并发表者,希望您尊重知识产权指出原作者出处CofeCut(原著)。--您知道GPL条款么?");
jTextArea2.setLineWrap(true);
jPanel5.setLayout(borderLayout8);
jPanel9.setLayout(borderLayout10);
jPanel10.setLayout(borderLayout11);
jLabel4.setText("帮助:什么是选择(Key) 文件:");
jTextField4.setBackground(SystemColor.info);
jTextField4.setText("此程序每次切割后都会产生一个以Key三个字母开头的文件");
jButton1.setIcon(new ImageIcon(CutOne.class.getResource("resources/close.jpg")));
jButton1.setText("本程序在GPL条款下分发,点击察看。");
jButton1.addActionListener(this);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenu1.add(jMenuItem1);
jTabbedPane1.add(jPanel2, " 说 明 ");
jPanel2.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jTabbedPane1.add(jPanel3, "分割文件 ");
jPanel3.add(jPanel6, BorderLayout.NORTH);
jPanel6.add(jPanel7, BorderLayout.NORTH);
jPanel6.add(jTextField1, BorderLayout.CENTER);
jPanel6.add(jLabel1, BorderLayout.WEST);
jPanel3.add(jButton4, BorderLayout.SOUTH);
jPanel3.add(jButton3, BorderLayout.EAST);
jPanel3.add(jTextField2, BorderLayout.CENTER);
jPanel3.add(jLabel2, BorderLayout.WEST);
jTabbedPane1.add(jPanel1, "合并文件 ");
jPanel1.add(jButton5, BorderLayout.EAST);
jPanel1.add(jButton6, BorderLayout.SOUTH);
jPanel1.add(jLabel3, BorderLayout.WEST);
jPanel1.add(jTextField3, BorderLayout.CENTER);
jPanel1.add(jPanel10, BorderLayout.NORTH);
jPanel10.add(jPanel9, BorderLayout.NORTH);
jPanel10.add(jTextField4, BorderLayout.CENTER);
jPanel10.add(jLabel4, BorderLayout.WEST);
jTabbedPane1.add(jPanel4, " 关 于 ");
jPanel4.add(jScrollPane2, BorderLayout.CENTER);
jScrollPane2.getViewport().add(jTextArea2, null);
jTabbedPane1.add(jPanel5, "GPL条款 ");
jPanel5.add(jButton1, BorderLayout.CENTER);
contentPane.add(jTabbedPane1, BorderLayout.CENTER);
jMenu2.add(jMenu3);
jMenu3.add(jMenuItem2);
jMenu3.add(jMenuItem3);
jMenu3.add(jMenuItem4);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main(String[] args){
CutOne t = new CutOne();
t.setLocation(50,30);
t.setSize(500,300);
t.show();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jButton3){
JFileChooser chooser = new JFileChooser();
int result;
chooser.setApproveButtonText("确定");
chooser.setDialogTitle("选择文件");
result = chooser.showOpenDialog(Wnd);
if(result==JFileChooser.APPROVE_OPTION)
{
file = chooser.getSelectedFile();
jTextField2.setText(file.getAbsolutePath());
/*System.out.println(file.getParent());
System.out.println(file.getAbsolutePath());
System.out.println(file.getName());*/
}
if(result==JFileChooser.CANCEL_OPTION)
{
jTextField2.setText("");
}
}
//cut
else if(e.getSource()==jButton4) {
file = new File(jTextField2.getText());
String SubString=file.getAbsolutePath().substring(0,file.getAbsolutePath().length()-file.getName().length());
if(file!=null&&!(jTextField1.getText().equals(""))&&file.isFile()){
CutFile cutFile = new CutFile(SubString,file.getName());
String size= jTextField1.getText();
char[] sizeArray = size.toCharArray();
boolean test = true;
for(int i=0;i<sizeArray.length;i ) {
if(!Character.isDigit(sizeArray[i])) {JOptionPane.showMessageDialog(Wnd,"数据不合法","CofeCut",
JOptionPane.ERROR_MESSAGE);
test=false;
break;
}
}
if(test) {
if(cutFile.ReadFile()) {
cutFile.FileNumber(new Float(size).floatValue());
cutFile.DoCut();
cutFile.CreateKey();
JOptionPane.showMessageDialog(Wnd,"分割顺利完成","CofeCut",
JOptionPane.INFORMATION_MESSAGE); }
else{JOptionPane.showMessageDialog(Wnd,"分割失败","CofeCut",
JOptionPane.INFORMATION_MESSAGE); }
}
}
else{JOptionPane.showMessageDialog(Wnd,"文件或目录不存在","CofeCut",
JOptionPane.ERROR_MESSAGE);
}
}
//Link
else if(e.getSource()==jButton5){
JFileChooser chooser = new JFileChooser();
int result;
chooser.setApproveButtonText("确定");
chooser.setDialogTitle("选择文件");
result = chooser.showOpenDialog(Wnd);
if(result==JFileChooser.APPROVE_OPTION)
{
file = chooser.getSelectedFile();
jTextField3.setText(file.getAbsolutePath());
}
if(result==JFileChooser.CANCEL_OPTION)
{
jTextField3.setText("");
}
}
else if(e.getSource()==jButton6){
file = new File(jTextField3.getText());
String SubString=file.getAbsolutePath().substring(0,file.getAbsolutePath().length()-file.getName().length());
if(file!=null&&file.isFile()){
linkFile = new LinkFile(SubString,file.getName());
if(linkFile.ReadKey()){
if(linkFile.DoLink()){
JOptionPane.showMessageDialog(Wnd,"合并文件成功完成","CofeCut",
JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(Wnd,"失败--请检查文件是否在同一目录中","CofeCut",
JOptionPane.ERROR_MESSAGE);
}
}
else{
JOptionPane.showMessageDialog(Wnd,"失败--Key文件被破坏","CofeCut",
JOptionPane.ERROR_MESSAGE);
}
}
else{
JOptionPane.showMessageDialog(Wnd,"文件或目录不存在","CofeCut",
JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource() == jMenuItem1){ System.exit(0);}
else if(e.getSource() == jButton1){ GPL gplwin= new GPL();
gplwin.setLocation(80,40);
gplwin.setSize(500,300);
gplwin.show();
}
//if Last }
}
////////////////////////////////////////////////////////
///////////////PPCutFile1.1此程序用于把文件切开///////////
////////////////////////////////////////////////////////
public class CutFile
{
CutFile(String FileDir,String FileName){
this.FileDir = FileDir;
this.FileName = FileName;
}
public boolean ReadFile(){
try{
InputFile = new File(FileDir FileName);
System.out.println(FileDir);
System.out.println(FileName);
if(InputFile.isFile()&&InputFile.canRead()&&InputFile.exists()){
fileInputStream = new DataInputStream(new BufferedInputStream(
new FileInputStream(InputFile)));
return true;
}
else{
System.out.println("文件不存在...");
return false;
}
}
catch(Exception e)
{return false;}
}
public int FileNumber(float FileWeight){
CountFileNumber = (int)(InputFile.length()/FileWeight);
if(InputFile.length()%FileWeight>0)
CountFileNumber ;
this.FileWeight=FileWeight;
return CountFileNumber;
}
public void DoCut(){
try{
int test;
for(int i=0;i<CountFileNumber;i ){
fileOutStream = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(new File(FileDir i FileName ".ccf"))));
for(int j=0;j<(int)FileWeight;j ){
test=fileInputStream.read();
if(test==-1)
break;
fileOutStream.write(test);
}
fileOutStream.flush();
}
fileInputStream.close();
fileOutStream.close();
}
catch(IOException e){
e.printStackTrace();
}
}
public void CreateKey(){
try{
fileOutStream = new DataOutputStream(
new FileOutputStream(new File(FileDir "key" FileName ".ccf")));
fileOutStream.writeChars("CofeCut1.0");
fileOutStream.writeInt(CountFileNumber);
fileOutStream.close();
}
catch(IOException e)
{e.printStackTrace();}
}
private int CountFileNumber;
private float FileWeight;
private String CreateFile;
private File InputFile;
private File OutputFile;
private String FileName;
private String FileDir;
private DataInputStream fileInputStream;
private DataOutputStream fileOutStream;
}
////////////////////////////////////////////////////////
/////////////PPLinkFile1.1此程序用于把文件合并////////////
////////////////////////////////////////////////////////
public class LinkFile
{
public LinkFile(String FileDir,String KeyFile)
{
this.FileDir=FileDir;
this.KeyFile=KeyFile;
Streams = new Vector();
}
public boolean ReadKey()
{
char[] KeyChar = new char[10];
try{
fileInputStream = new DataInputStream(
new FileInputStream(FileDir KeyFile));
for(int i=0;i<10;i ){
KeyChar[i] =fileInputStream.readChar();
}
if(TheKey.equals(new String(KeyChar))){
CountFileNumber = fileInputStream.readInt();
return true;
}
System.out.println("KeyFile has broken!");
return false;
}
catch(IOException e)
{e.printStackTrace();return false;}
}
public boolean DoLink(){
try{
FileName = KeyFile.substring(3,KeyFile.length());
for(int i=0;i<CountFileNumber;i ){
if(new File(FileDir i FileName).isFile()){
Streams.addElement(new BufferedInputStream( new FileInputStream(FileDir i FileName)));}
else
{return false;}
}
FileName = KeyFile.substring(0,KeyFile.length()-4);
fileOutStream= new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(new File(FileDir FileName))));
AddStream = new SequenceInputStream(Streams.elements());
int c;
while((c = AddStream.read())!=-1){
fileOutStream.write(c);
}
AddStream.close();
fileOutStream.close();
return true;
}
catch(IOException e)
{e.printStackTrace();return false;}
}
private Vector Streams;
private int CountFileNumber;
private DataOutputStream fileOutStream = null;
private DataInputStream fileInputStream = null;
private File OutputFile = null;
private String KeyFile = null;
private String FileDir = null;
private String TheKey = "CofeCut1.0";
private String FileName = null;
private SequenceInputStream AddStream = null;
}
/////////////////////////////////////////////////////////
/////////PPKeyIn1.1此程序用于从控制台得到数据///////////////
/////////////////////////////////////////////////////////
public class KeyIn
{
public KeyIn(){KeyBoardInput = new BufferedReader
(new InputStreamReader(System.in));}
//从控制台得到float类型的数据
public float KeyInFloat(){
try{
for(;;){
Input = KeyBoardInput.readLine();
char[]mychar=Input.toCharArray();
for(int i=0;i<mychar.length;i ){
ischar=Character.isDigit(mychar[i])||mychar[i]=='.';
if(ischar==false){
Input ="some chars are not digit";
break;
}
}
if(Input.length()>20||Input.equals("")){
System.out.println("输入数据不合法");
}
else{
Float floater = new Float(Input);
theFloat=floater.floatValue();
return theFloat;
}
}
}
catch(IOException e){
e.printStackTrace();
return -1;
}
}
//从控制台得到int类型的数据
public int KeyInInt(){
try{
for(;;){
Input = KeyBoardInput.readLine();
char[]mychar=Input.toCharArray();
for(int i=0;i<mychar.length;i ){
ischar=Character.isDigit(mychar[i]);
if(ischar==false){
Input ="some chars are not digit";
break;
}
}
if(Input.length()>10||Input.equals("")){
System.out.println("输入数据不合法");
}
else{
Integer integer = new Integer(Input);
theInt=integer.intValue();
return theInt;
}
}
}
catch(IOException e){
e.printStackTrace();
return -1;
}
}
public String KeyInString(){
try{
return KeyBoardInput.readLine();
}
catch(IOException e)
{e.printStackTrace();return null;}
}
private BufferedReader KeyBoardInput;
private String Input;
private float theFloat;
private boolean ischar;
private int theInt;
}
//Last }
}