//////////////////////////////////////////////切割
package 文件的切割与和;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Test3 implements ActionListener{
Frame frame;
TextField t1,t2;
Button btn1,btn2;
String string,string1;
Panel p1,p2,p3,p4;
Label l1,l2;
public Test3() {
frame = new Frame("把你割成粉碎");
t1 = new TextField(30);
t2 = new TextField(30);
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p4 = new Panel();
l1 = new Label("文件读取路径名:");
l2 = new Label("切割到:");
btn1 = new Button("切割吧");
btn2 = new Button("合体");
btn1.addActionListener(this);
btn2.addActionListener(this);
frame.add(p2,"Center");
p2.add(p3,"North");
p3.add(l1);
p3.add(t1);
p2.add(p4,"South");
p4.add(l2);
p4.add(t2);
frame.add(p1,"South");
p1.add(btn1,"West");
p1.add(btn2,"East");
frame.setSize(600,200);
frame.setLocation(200,200);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void test3() {
try {
string = t1.getText();
string1 = t2.getText();
FileInputStream fis = new FileInputStream(string);
FileOutputStream fos = null;
byte[] buf = new byte[1024 * 1024];
int len = 0;
int count = 1;
while ((len = fis.read(buf)) != -1) {
fos = new FileOutputStream(string1 + (count++) + ".part");
fos.write(buf, 0, len);
fos.close();
}
fis.close();
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
new Test3();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btn1){
test3();
}else if(e.getSource()==btn2){
new Test1();
frame.setVisible(false);
}
}
}
////////////////////////////////////////////////////组合
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class Test1 implements ActionListener {
Frame frame;
TextField t1,t2,t3;
Button btn2;
String string,string1;
Panel p1,p2,p3;
Label l1,l2,l3;
int i;
public Test1() {
frame = new Frame("超级赛亚人");
t1 = new TextField(20);
t2 = new TextField(20);
t3 = new TextField(5);
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
btn2 = new Button("合体吧");
btn2.addActionListener(this);
l1 = new Label("文件来源:");
l2 = new Label("存入路径和名称(MP3格式):");
l3 = new Label("文件数:");
frame.add(p1,"Center");
p1.add(p2,"North");
p1.add(p3,"South");
p2.add(l1);
p2.add(t1);
p2.add(l3);
p2.add(t3);
p3.add(l2);
p3.add(t2);
frame.add(btn2, "South");
frame.setSize(600, 200);
frame.setLocation(200, 200);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void test1() {
try {
string = t1.getText();
string1 = t2.getText();
i = Integer.parseInt(t3.getText());
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
for (int x = 1; x < i+1; x++)
al.add(new FileInputStream(string+x+".part"));
final Iterator<FileInputStream> it = al.iterator();
Enumeration<FileInputStream> en = new Enumeration<FileInputStream>() {
public boolean hasMoreElements() {
return it.hasNext();
}
public FileInputStream nextElement() {
return it.next();
}
};
SequenceInputStream sis = new SequenceInputStream(en);
FileOutputStream fos = new FileOutputStream(string1);
byte[] buf = new byte[1024 * 4];
int len = 0;
while ((len = sis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
sis.close();
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
new Test1();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btn2){
test1();
}
}
}