代码如下:
public class SplitFileDemo {
public static void main(String[] args) throws IOException{
File file_1 = new File("E:\\Mine Mine.mp3");
//splitFile(file_1);
merge(11);
}
public static void merge(int count) throws IOException {
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
for(int i = 1; i <= count ; i ++) {
al.add(new FileInputStream("E:\\mine mine\\" +count + ".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("E:\\mine mine\\mine mine.mp3");
byte[] buf = new byte[1024];
int len = 0;
while((len = sis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
sis.close();
}
public static void splitFile(File file_1) throws IOException{
FileInputStream fis = new FileInputStream(file_1);
FileOutputStream fos = null;
byte[] buf = new byte[1024*1024];
int len = 0;
int count = 1;
while((len = fis.read(buf)) != -1) {
fos = new FileOutputStream("E:\\mine mine\\" + (count++) + ".part");
fos.write(buf, 0, len);
fos.close();
}
fis.close();
}
}
作者: 刘基军 时间: 2012-1-13 16:22
public static void merge(int count) throws IOException {
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
for(int i = 1; i <= count ; i ++) {
al.add(new FileInputStream("E:\\mine mine\\" +count + ".part")); //这边应该是:i
} 作者: 刘明瑞 时间: 2012-1-13 16:43
刘基军 发表于 2012-1-13 16:22
public static void merge(int count) throws IOException {
ArrayList al = new ArrayLis ...